1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
public class JPiece extends JPanel {
private int p_choix, g_x, g_y;
public JPiece(){
}
public JPiece(int choix, int x, int y) {
super();
this.setLayout(new BorderLayout());
JLayeredPane lp = new JLayeredPane();
g_x = x;
g_y = y;
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JPanel panel5 = new JPanel();
panel1.setLayout(new BorderLayout());
panel2.setLayout(new BorderLayout());
panel3.setLayout(new BorderLayout());
panel4.setLayout(new FlowLayout());
panel5.setLayout(new GridLayout(2,0));
// chargement des options multimédia
JLabel label1 = new JLabel("Multimédia");
ImageIcon im1 = new ImageIcon("lecture.gif");
im1 = redim(im1, 60, 60);
JButton lecture = new JButton(im1);
ImageIcon im2 = new ImageIcon("stop.gif");
im2 = redim(im2, 60, 60);
JButton stop = new JButton(im2);
// on met dans les pannels
panel5.add(lecture);
panel5.add(stop);
panel4.add(label1);
panel3.add(panel4, BorderLayout.NORTH);
panel3.add(panel5, BorderLayout.CENTER);
panel1.add(panel3, BorderLayout.EAST);
panel1.setBounds(0, 0, g_x, g_y);
lp.add(panel1, new Integer(0));
// on dessine la pièce
p_choix = choix;
JAffichePiece piece = new JAffichePiece(g_x, g_y, p_choix);
piece.setOpaque(false);
piece.setBounds(0, 0, g_x, g_y);
lp.add(piece, new Integer(1));
if(p_choix == 0){
JAfficheBouton bouton = new JAfficheBouton(g_x, g_y, p_choix);
bouton.setBounds(0, 0, g_x, g_y);
lp.add(bouton, new Integer(2));
}
this.add(lp);
this.setVisible(true);
}
private static ImageIcon redim(ImageIcon source, int heigth, int width){
return new ImageIcon(source.getImage().getScaledInstance(width, heigth, Image.SCALE_SMOOTH));
}
} |
Partager