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 java.awt.Color;
public class exo3 extends JFrame{
JPanel leconteneur =new JPanel();
JButton lebtn=new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
public exo3(){
this.setTitle("Fenetre gridbaglayout");
this.setSize(500, 420);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
leconteneur.setBackground(Color.RED);
leconteneur.setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets=new Insets(15, 5, 0, 0);
leconteneur.add(button3,gbc);
gbc1.gridx=0;
gbc1.gridy=1;
//gbc1.insets=new Insets(15, 5, 0, 0);
leconteneur.add(lebtn,gbc);
gbc.gridx = 1;
gbc.gridy = 1;
//gbc.insets=new Insets(15, 50, 0, 0);
leconteneur.add(button2,gbc);
this.setContentPane(leconteneur);
this.setVisible(true);
}
public static void main(String[] args) {
new exo3();
}
} |
Partager