How to make a JFrame button open another JFrame class in Netbeans?

↘锁芯ラ 提交于 2019-11-26 19:45:50

问题


I have a JFrame class and it was made in the design section on Netbeans. I am trying to make a log in button that takes closes the current frame and opens another, is there anyway I can do that?

I have tried:

JFrame frame = new JFrame(); 

But I want it to be editable in the design section!


回答1:


Double Click the Login Button in the NETBEANS or add the Event Listener on Click Event (ActionListener)

btnLogin.addActionListener(new ActionListener() 
{
    public void actionPerformed(ActionEvent e) {
        this.setVisible(false);
        new FrmMain().setVisible(true); // Main Form to show after the Login Form..
    }
});



回答2:


new SecondForm().setVisible(true);

You can either use setVisible(false) or dispose() method to disappear current form.




回答3:


This link works with me: video

The answer posted before didn't work for me until the second click

So what I did is Directly call:

        new NewForm().setVisible(true);

        this.dispose();//to close the current jframe



回答4:


JFrame.setVisible(true);

You can either use setVisible(false) or dispose() method to disappear current form.



来源:https://stackoverflow.com/questions/17637195/how-to-make-a-jframe-button-open-another-jframe-class-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!