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 67 68 69 70
| import javax.swing.*;
import java.awt.*;
class autretest{
private JPanel principal=null,un=null,deux=null,trois=null;
private JFrame frame=null;
private GridBagLayout layout=null,layout1=null;
//private GridBagConstraints c=null,d=null;
private JLabel label1=null,label2=null,label3=null,label4=null,label5=null;
public autretest(){
frame=new JFrame(" Un test de fentre");
frame.setSize(1280,800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
principal=new JPanel();
principal.setBackground(Color.BLUE);
layout=new GridBagLayout();
principal.setLayout(layout);
GridBagConstraints c=new GridBagConstraints();
un=new JPanel();
un.setBackground(Color.GREEN);
c.gridx=0;
c.gridy=0;
//c.gridwidth=200;
//c.gridheight=200;
c.anchor = GridBagConstraints.CENTER;
//c.fill=GridBagConstraints.BOTH;
layout.setConstraints(un,c);
principal.add(un);
GridBagConstraints r=new GridBagConstraints();
deux=new JPanel();
deux.setBackground(Color.YELLOW);
r.gridx=0;
r.gridy=1;
//r.gridwidth=100;
//r.gridheight=100;
//r.weightx=100;
//r.weighty=100;
r.anchor=GridBagConstraints.WEST;
//r.fill=GridBagConstraints.EAST;
layout.setConstraints(deux,r);
principal.add(deux);
GridBagConstraints f=new GridBagConstraints();
trois=new JPanel();
f.gridx=1;
f.gridy=1;
//f.gridwidth=100;
//f.gridheight=100;
f.anchor=GridBagConstraints.EAST;
//f.anchor=GridBagConstraints.WEST;
layout.setConstraints(trois,f);
principal.add(trois);
frame.setContentPane(principal);
}
public static void main(String [] arg){
autretest at=new autretest();
}
} |
Partager