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
| import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
class MaFenetre extends JFrame implements ActionListener
{
public MaFenetre()
{
setTitle("Titre de ma fenêtre");
setSize(600,300);
setVisible(true);
Container page = getContentPane();
page.setLayout(new FlowLayout());
monBouton = new JButton("Creation boutons");
page.add(monBouton);
monBouton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == monBouton)
{
bouton++;
b = new JButton("B" + bouton);
page.add(b);
b.addActionListener(this);
}
}
private JButton monBouton, b;
private Container page;
private int bouton = 0;
}
public class premier
{
public static void main(String args[])
{
MaFenetre g = new MaFenetre();
}
} |