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
|
import java.awt.*;
import javax.swing.*;
import panels.*;
public class CartePlacement extends JFrame {
private JPanel cartes;
private JPanel menu;
public CartePlacement() {
super("Essais CardLayout");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.creerInterface();
this.pack();
this.setVisible(true);
}
public void creerInterface() {
JPanel pan = (JPanel) this.getContentPane();
menu = new JpMenu();
JPanel carte1 = new JPanel();
carte1.setLayout(new FlowLayout(FlowLayout.LEFT));
carte1.add(new JLabel("Formulaire n°1") );
carte1.add(new JButton("Premier Bouton"));
carte1.add(new JTextField(20) );
JPanel carte2 = new JPanel();
carte2.add(new JLabel("Formulaire n°2"));
carte2.add(new JTextField(20));
carte2.add(new JButton("Second bouton"));
cartes = new JPanel(new CardLayout());
cartes.add(carte1, "f1");
cartes.add(carte2, "f2");
pan.add(menu, BorderLayout.WEST);
pan.add(cartes, BorderLayout.CENTER);
}
public static void main(String[] args) {
CartePlacement test = new CartePlacement();
}
public void changerCarte(String nomCarte){
CardLayout carte = (CardLayout) (cartes.getLayout());
carte.show(cartes, nomCarte);
}
} |
Partager