bonjour, voici mon code :
mon problème est que si j'enlève le newPanel le oldPanel qui doit s'afficher en tant que contentPane s'affiche correctement, mais dès que je remet le code du newPanel, le oldPanel cesse d'exister et ne m'affiche plus rien, je ne comprends pas d'où ça vient.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; class FenetrePoke extends JFrame{ public JPanel contentPane = new JPanel();; public CardLayout CL; public JPanel boutons; public JPanel oldPanel = new JPanel(); public JPanel newPanel = new JPanel(); public FenetrePoke() { this.setTitle("Appli Pokémon"); this.setSize(1500,1200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.getContentPane().setLayout(new BorderLayout()); JPanel boutons = new JPanel(); JButton Pokedex = new JButton("Pokedex"); boutons.setBackground(Color.red); Pokedex.addActionListener(new SwitchFrame()); boutons.add(Pokedex); boutons.add(new JButton("Strat")); boutons.add(new JButton("Strat 2")); oldPanel.setBackground(Color.green); oldPanel.setLayout(new BorderLayout()); oldPanel.add(boutons, BorderLayout.NORTH); newPanel.setBackground(Color.blue); newPanel.setLayout(new BorderLayout()); newPanel.add(boutons, BorderLayout.NORTH); CL = new CardLayout(); contentPane.setLayout(CL); contentPane.add(oldPanel,"prem"); contentPane.add(newPanel,"deux"); this.setContentPane(oldPanel); this.setVisible(true); } class SwitchFrame implements ActionListener{ public void actionPerformed(ActionEvent e) { CL.show(contentPane, "deux"); } } } public class AppPoke { public static void main(String[] args) { FenetrePoke fen = new FenetrePoke(); } }
Partager