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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| public Acceuil2() {
ImageBackground container = new ImageBackground(new ImageIcon("image1.jpg").getImage(),false,false);
// paramètrage fenêtre
this.setTitle("");
this.setSize(900, 550);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setContentPane(container);
this.setVisible(true);
// composants dans la fenêtre
createContent(container);
}
private void createContent(JPanel panel) {
// on utilise un BorderLayout pour gérer la position des composants
panel.setLayout(new BorderLayout(HGAP, VGAP));
// en haut
add(creerTitre(),BorderLayout.NORTH);
// à droite
add(creerBoutons(),BorderLayout.EAST);
// au centre
add(creerTexte(),BorderLayout.CENTER);
//add(creerTitre1(),BorderLayout.SOUTH);
add(crerBoutons(),BorderLayout.WEST);
}
private JComponent creerBoutons() {
Dimension dimension = new Dimension(100,170);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // 1 colonne de boutons
panel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 10;
gbc.gridy = GridBagConstraints.RELATIVE;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(HGAP,VGAP,20,10); // espacement
Dimension space = new Dimension(HGAP,VGAP);
panel.add(Box.createRigidArea(space)); // permet d'avoir un espacement
// pareil pour les autres
JButton bouton2 = new JButton("femme");
bouton2.setPreferredSize(dimension);
bouton1.addActionListener(this);
panel.add(bouton2, gbc);
panel.add(Box.createRigidArea(space)); // permet d'avoir un espacement
JButton bouton4 = new JButton("homme");
bouton4.setPreferredSize(dimension);
panel.add(bouton4, gbc);
return panel;
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == bouton1)
{
if(birdButton.isSelected())
{
try {
Affichage.affichage();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if (catButton.isSelected())
{
try {
Fichi.affichage();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
try {
Affichage1.affichage1();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} |
Partager