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
| import javax.swing.*;
import java.awt.*;
public class Fenetre extends JFrame{
public static int NBOUTONS = 4;
private JButton boutons[];
private GridLayout lay = new GridLayout (2,2,5,5);
private JPanel panel = new JPanel(lay);
public Fenetre(){
setTitle("Premiere interface graphique");
setSize(600,600);
Container contenu = getContentPane();
contenu.add(panel);
contenu.setLayout(lay);
panel.setBackground(Color.yellow);
boutons = new JButton[NBOUTONS] ;
for (int i=0; i<NBOUTONS ; i++){
boutons[i] = new JButton ("Boutons" + i);
panel.add(boutons[i]);
}
}
static public void main(String[] args) {
Fenetre f = new Fenetre();
f.setVisible(true);
}
} |
Partager