Including more than two Panels in a JFrame?

后端 未结 3 591
忘了有多久
忘了有多久 2021-01-06 06:05

We are working on a project where we encountered a problem with including more than two Panels on the same JFrame .What we want is one Panel above the other.

Can the

3条回答
  •  耶瑟儿~
    2021-01-06 06:50

    //you can also use card Layout, that enables you to add multiple card-panels on Main panel.

    CardLayout cl;
    JPanel main,one,two,three;
    JButton button1,button2;
    
    cl = new CardLayout();
    main.setLayout(cl);
    
    main.add(one,"1");
    main.add(two,"2");
    main.add(three,"3");
    
    cl.show(main,"1");
    
    public void actionPerformed(ActionEvent e){
     if(e.getSource() == button1)
         cl.show(main,"2");
     else if(e.getSource() == button2)
         cl.show(main,"3");
    }
    

提交回复
热议问题