frame 2 inside frame 1

后端 未结 2 1881
鱼传尺愫
鱼传尺愫 2021-01-16 22:39

I have 2 classes; Students and RegisterStudents, and hence 2 different main_panel(Class 1) and panel_1 (Class 2). What I am trying to do is, when a button on the Students In

2条回答
  •  孤独总比滥情好
    2021-01-16 23:10

    JButton btnNewButton = new JButton("Register Student");
    btnNewButton.addMouseListener(new MouseAdapter() {
       @Override
       public void mouseClicked(MouseEvent arg0) {
    
    
           Students main_panel = new Students();
           RegisterStudent panel_1 = new RegisterStudent();
           main_panel.add(panel_1);
           panel.add(main_panel); // ADD THIS LINE
       }
    });
    btnNewButton.setBounds(0, 162, 167, 37);
    panel.add(btnNewButton);
    

    You were initializing the new main_panel, and new panel_1, and adding panel_1 to main_panel but then you weren't doing anything with the new main_panel.

    Also, I highly suggest naming your variables otherwise - these names are very non-intuitive.

提交回复
热议问题