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
| private List listeDS;
private JButton buttonConnect, buttonDisconnect;
private JTextField champ1Connect,champ2Connect;
public Constructeur() {
//initialisation, panels,etc ...
listeDS = new List();
listeDS.add("el1",0);
listeDS.add("el2",1);
listeDS.add("el3",2);
listeDS.add("el4",3);
panel.add(listeDS);
listeDS.addActionListener(this);
listeDS.addItemListener(this);
champ1Connect = new JTextField("",15);
p.add(champ1Connect);
pchamp2=new JTextField("",8);
p.add(champ2);
buttonConnect = new JButton("Connexion");
p.add(buttonConnect);
buttonConnect.addActionListener(this);
buttonDisconnect = new JButton("Déconnexion");
p.add(buttonDisconnect);
buttonDisconnect.addActionListener(this);
}
//plus bas, les listener :
public void itemStateChanged(ItemEvent e) {
Object o = e.getItemSelectable();
if (o == listeDS){
selectionDS();
//selectionDS modifie champ1 et champ2 et j'y accède ensuite dans d'autres
//méthodes
}
} |
Partager