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
| import javax.swing.*;
import java.awt.*;
class MaFenetre extends JFrame
{
public static int x[] = { 0, 3, 3, 0, 0, 3};
public static int y[] = { 0, 0, 1, 2, 3, 2};
public static int larg[]= { 3, 2, 2, 3, 3, 2};
public static int haut[]= { 2, 1, 1, 1, 1, 2};
public static int px[] = {60,40, 0, 0, 0, 0};
public static int py[] = { 0,25,25,25,25, 0};
public static JPanel pan1;
public static JPanel pan2;
public static JPanel pan3;
public static JPanel pan4;
public static JPanel pan5;
public static JPanel pan6;
public MaFenetre()
{
setTitle("Exemple");
setSize(1000,700);
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);
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];
if (i==0) contenu.add( pan1, c );
if (i==1) contenu.add( pan2, c );
if (i==2) contenu.add( pan3, c );
if (i==3) contenu.add( pan4, c );
if (i==4) contenu.add( pan5, c );
if (i==5) contenu.add( pan6, c );
}
}
}
public class GUI_complique_01
{
public static void main (String args[])
{
MaFenetre fen = new MaFenetre();
fen.setVisible(true);
}
} |
Partager