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
| import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
class Fen2Bouton extends JFrame implements ActionListener
{
public Fen2Bouton()
{
setTitle("Premier Bouton");
setSize(300, 200) ;
monBouton1 = new JButton ("BOUTON A") ;
monBouton2 = new JButton ("BOUTON B") ;
getContentPane().setLayout(new FlowLayout ());
getContentPane().add(monBouton1) ;
getContentPane().add(monBouton2) ;
monBouton1.addActionListener(this);
monBouton2.addActionListener(this);
}
public void actionPerformed(ActionEvent ev)
{
Object source = ev.getSource();
if(source == monBonton1)
{
System.out.println("action sur bouton numero 1");
}
if(source == monBonton2)
{
System.out.println("action sur bouton numero 2");
}
}
private JButton monBouton1, monBouton2;
}
public class listing5
{
public static void main (String args[])
{
Fen2Bouton fen = new Fen2Bouton();
fen.setVisible(true);
}
} |
Partager