我想通过单击 JPanel 上的按钮在 JPanel 之间切换。
例如:我有一个带有 JButton simknop 的 JPanel sim 和带有 JButton helpknop 的 JPanel 帮助我想通过单击按钮在这两个 JPanel 之间切换。当我点击 JButton simknop JPanel 帮助应该出现,当我点击 JButton 帮助 JPanel sim 应该出现。
您可以在下面找到不同的类:
public class main extends JFrame
{
JPanel cards;
sim sim;
help help;
public main()
{
this.setSize(1024,768);
//this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Crazy Bombardement");
this.setLocation(800, 100);//standaard in de hoek van het scherm
cards = new JPanel();
cards.setLayout(new CardLayout());
sim = new sim();
help = new help();
cards.add(sim, "SIM");
cards.add(help, "HELP");
this.add(cards);
this.setVisible(true); …Run Code Online (Sandbox Code Playgroud)