package org.llgc; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.SwingConstants; @SuppressWarnings ("serial") public class Swing extends JFrame { public static void main (final String[] args) { new Swing (); } public Swing () { initialize (); } private void initialize () { setTitle ("Bonjour"); // addWindowListener (new ActionClose()); setDefaultCloseOperation (DISPOSE_ON_CLOSE); getContentPane ().setLayout (new BorderLayout ()); // Le add place les // composants les uns à la suite des autres plutôt que les uns sur les // autres. getContentPane ().add (new JLabel ("Titre", SwingConstants.CENTER), BorderLayout.NORTH); JPanel pnlSouth = new JPanel (new GridLayout (0, 2, 12, 12)); pnlSouth.setDoubleBuffered (true); JLabel lbl = new JLabel ("Nom"); lbl.setHorizontalAlignment (SwingConstants.CENTER); pnlSouth.add (lbl, BorderLayout.CENTER); JTextField bt = new JTextField (25); pnlSouth.add (bt, BorderLayout.CENTER); lbl = new JLabel ("Pays"); lbl.setHorizontalAlignment (SwingConstants.CENTER); pnlSouth.add (lbl, BorderLayout.CENTER); JComboBox lstPays = new JComboBox (); lstPays.addItem ("France"); lstPays.addItem ("Espagne"); lstPays.addItem ("Angleterre"); lstPays.addItem ("Belgique"); pnlSouth.add (lstPays, BorderLayout.CENTER); lbl = new JLabel ("Civilité"); lbl.setHorizontalAlignment (SwingConstants.CENTER); pnlSouth.add (lbl, BorderLayout.CENTER); JPanel pnlCiv = new JPanel (new BorderLayout ()); JRadioButton optMonsieur = new JRadioButton ("Monsieur"); JRadioButton optMadame = new JRadioButton ("Madame"); ButtonGroup grpCivil = new ButtonGroup (); grpCivil.add (optMadame); grpCivil.add (optMonsieur); pnlCiv.add (optMadame, BorderLayout.EAST); pnlCiv.add (optMonsieur, BorderLayout.WEST); pnlSouth.add (pnlCiv, BorderLayout.CENTER); JPanel pnl2 = new JPanel (); // pnl2.setSize (new Dimension (500, 500)); // pnlSouth.setSize (new Dimension (500, 500)); pnl2.add (pnlSouth, BorderLayout.CENTER); pnlSouth.setLayout (new GridLayout (0, 2, 20, 20)); getContentPane ().add (pnl2, BorderLayout.CENTER); pnlSouth = new JPanel (new FlowLayout ()); JButton button1 = new JButton (new ActionClose ("Fermer")); JButton button2 = new JButton (new ActionClose ("Fermer bis")); pnlSouth.add (button1, BorderLayout.WEST); pnlSouth.add (button2, BorderLayout.EAST); getContentPane ().add (pnlSouth, BorderLayout.SOUTH); // setSize (280, 100); pack (); setVisible (true); } private class ActionClose extends AbstractAction { public ActionClose (String name) { super (name); } @Override public void actionPerformed (ActionEvent arg0) { dispose (); } } }