小编kha*_*led的帖子

CardLayout,通过ButtonClick在JPanels之间切换

我想通过单击 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)

java swing awt layout-manager cardlayout

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

awt ×1

cardlayout ×1

java ×1

layout-manager ×1

swing ×1