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
| import javax.swing.*;
import java.awt.*;
class MaFenetre extends JFrame
{
public JPanel pan1;
public JPanel pan2;
public JPanel pan3;
public JPanel pan4;
public JPanel pan5;
public JPanel pan6;
public MaFenetre()
{
setTitle("Exemple");
setSize(800,600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container contenu = getContentPane();
GridBagLayout g = new GridBagLayout();
contenu.setLayout(g);
GridBagConstraints c = new GridBagConstraints();
c.fill = c.BOTH ;
pan1=new JPanel(); pan1.setBackground(Color.blue);
pan2=new JPanel(); pan2.setBackground(Color.white);
pan3=new JPanel(); pan3.setBackground(Color.black);
pan4=new JPanel(); pan4.setBackground(Color.red);
pan5=new JPanel(); pan5.setBackground(Color.yellow);
pan6=new JPanel(); pan6.setBackground(Color.green);
int x[] = { 0, 3, 3, 0, 0, 3};
int y[] = { 0, 0, 1, 2, 3, 2};
int larg[]= { 3, 2, 2, 3, 3, 2};
int haut[]= { 2, 1, 1, 1, 1, 2};
int px[] = {60,40, 0, 0, 0, 0};
int py[] = { 0,25,25,25,25, 0};
for (int i=0; i<x.length; i++)
{
c.gridx=x[i];
c.gridy=y[i];
c.gridwidth=larg[i];
c.gridheight=haut[i];
c.weightx=px[i];
c.weighty=py[i];
switch(i)
{
case 0: contenu.add( pan1, c );
case 1: contenu.add( pan2, c );
case 2: contenu.add( pan3, c );
case 3: contenu.add( pan4, c );
case 4: contenu.add( pan5, c );
case 5: contenu.add( pan6, c );
}
}
}
}
public class GUI_complique_01
{
public static void main (String args[])
{
MaFenetre fen = new MaFenetre();
fen.setVisible(true);
}
} |
Partager