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

2022-01-24 00:00:00 netbeans java swing jframe

我有一个 JFrame 类,它是在 Netbeans 的设计部​​分制作的.我正在尝试制作一个登录按钮来关闭当前框架并打开另一个框架,无论如何我可以这样做吗?

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?

我试过了:

JFrame frame = new JFrame(); 

但我希望它在设计部分是可编辑的!

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

推荐答案

在NETBEANS中双击登录按钮或者添加点击事件监听器(ActionListener)

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..
    }
});

相关文章