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
| public class CommandScreen extends JFrame implements ActionListener{
JPanel panneau = new JPanel();
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
// Les JLabel, JButton implémentés
public CommandScreen() {
panneau.setLayout(layout);
ajouterComposant(bouton1, 3, 0, 2, 1);
ajouterComposant(label1, 0, 1, 2, 1);
// etc pour chaque composant
this.setContentPane(panneau);
this.setBounds(200, 200, 600, 600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("Ecran de commandes");
this.setVisible(true);
}
public void ajouterComposant(Component composant, int colonne, int ligne, int largeur, int hauteur)
{
gbc.gridx = colonne;
gbc.gridy = ligne;
gbc.gridwidth = largeur;
gbc.gridheight = hauteur;
gbc.insets = new Insets(20, 20, 0, 0);
layout.setConstraints(composant, gbc);
panneau.add(composant);
}
} |
Partager