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
| import javax.swing.*;
import java.awt.*;
class MaFenetre extends JFrame
{
public static int x[] = { 0, 0, 1};
public static int y[] = { 0, 1, 0};
public static int larg[]= { 1, 1, 3};
public static int haut[]= { 1, 2, 3};
public static int px[] = {20,20,60};
public static int py[] = {20,40,60};
public static JPanel pan1;
public static JPanel pan2;
public static JPanel pan3;
public MaFenetre()
{
setTitle("Exemple");
setSize(800,500);
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.red);
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 ); break;
case 1: contenu.add( pan2, c ); break;
case 2: contenu.add( pan3, c ); break;
}
}
}
}
public class GUI_complique_01
{
public static void main (String args[])
{
MaFenetre fen = new MaFenetre();
fen.setVisible(true);
}
} |
Partager