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
|
public class TraceIHM2 extends JFrame implements ActionListener{
JPanel pan = new JPanel();
JWindow win = null;
JButton but =null;
JButton but1 =null;
JList list=null;
public void draw(){
list = new JList();
DefaultListModel listModel = new DefaultListModel();
list.setModel(listModel);
listModel.addElement("UN");
listModel.addElement("DEUX");
listModel.addElement("TROIS");
win = new JWindow(this);
win.getContentPane().add(list);
win.setSize(300,200);
win.setLocation(200,200);
but = new JButton("depart");
but.addActionListener(this);
but1 = new JButton("stop");
but1.addActionListener(this);
pan.add(but);
pan.add(but1);
this.getContentPane().add(pan);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==but){
win.setVisible(true);
win.pack();
}
if (e.getSource()==but1){
win.setVisible(false);
}
}
public static void main(String[] args) {
TraceIHM2 toto = new TraceIHM2();
toto.draw();
}
} |
Partager