简体   繁体   English

如何使JFrame按钮在Netbeans中打开另一个JFrame类?

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

I have a JFrame class and it was made in the design section on Netbeans. 我有一个JFrame类,它是在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! 但我希望它在设计部分可以编辑!

Double Click the Login Button in the NETBEANS or add the Event Listener on Click Event (ActionListener) 双击NETBEANS中的登录按钮或在Click事件上添加事件监听器(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..
    }
});

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
new SecondForm().setVisible(true);

您可以使用setVisible(false)dispose()方法来消除当前表单。

JFrame.setVisible(true);

您可以使用setVisible(false)dispose()方法来消除当前表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM