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 54 55 56 57 58 59 60 61 62 63 64 65 66
|
[package allumettes;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class main2 extends JFrame{
public main2(){
this.setSize(500 , 500);
this.setTitle("Title");
JPanel jp = new JPanel(new GridBagLayout());
this.getContentPane().add(jp ,BorderLayout.PAGE_START);
this.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel[] lj = new JLabel[5];
for (int i= 0 ; i< 5 ; i++){
lj[i] = new JLabel(" this a message " + i ) ;
}
c.gridx = 0;
c.gridy = 10;
c.weightx = 50;
c.weighty = 60;
jp.add(lj[0] ,c);
c.gridx = 0;
c.gridy = 20;
c.weightx = 50;
c.weighty = 60;
jp.add(lj[1] ,c);
c.gridx = 50;
c.gridy = 100;
c.weightx = 50;
c.weighty = 60;
jp.add(lj[2] ,c);
c.gridx = 0;
c.gridy = 30;
c.weightx = 50;
c.weighty = 60;
jp.add(lj[3] ,c);
c.gridx = 0;
c.gridy = 40;
c.weightx = 50;
c.weighty = 60;
jp.add(lj[4] ,c);
}
public static void main(String[] args ){
JFrame jf = new main2();
jf.setVisible(true);
jf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
} |
Partager