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
| public class ChoixPlateau extends JPanel implements ActionListener
{
JLabel picture;
//TODO : Problème du master
//Master master = new Master();
public ChoixPlateau()
{
super(new BorderLayout());
String[] Strings = {"Plateau 1","Plateau 2","Plateau 3","Plateau 4","Plateau 5","Plateau 6","Plateau 7","Plateau 8","Plateau 9","Plateau 10"};
JComboBox List = new JComboBox(Strings);
List.setSelectedIndex(0);
List.addActionListener(this);
// Set up the picture.
picture = new JLabel();
picture.setFont(picture.getFont().deriveFont(Font.ITALIC));
picture.setHorizontalAlignment(JLabel.CENTER);
updateLabel(Strings[List.getSelectedIndex()]); // On appelle la fonction pour charger les images
picture.setPreferredSize(new Dimension(175,175));
// Position du label et du comboBox
add(picture, BorderLayout.PAGE_START);
add(List, BorderLayout.PAGE_END);
}
public void actionPerformed(ActionEvent e)
{
JComboBox cb = (JComboBox)e.getSource();
String Name = (String)cb.getSelectedItem();
master.plateau.nom = Name; System.out.println(""+master.plateau.nom);
// Ici, ci-dessus, il ne veut pas reconnaitre le master.
updateLabel(Name);
}
protected void updateLabel(String name)
{
ImageIcon icon = new ImageIcon("./images/Plateaux/Petits/" + name + ".gif");
picture.setIcon(icon);
if (icon != null)
{
picture.setText(null);
}
else
{
picture.setText("Image not found");
}
}
} |
Partager