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
| public class Essai extends JFrame implements ItemListener{
private JComboBox combo;
public Essai() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
combo=new JComboBox();
combo.addItem("UN");
combo.addItem("DEUX");
this.getContentPane().add(combo);
combo.addItemListener(this);
this.getContentPane().setLayout(new FlowLayout());
}
public void itemStateChanged(ItemEvent e) {
if(e.getSource()==combo){
System.out.println("combo changed");
}
}
} |