Ultrabyte
Ultrabyte

Reputation: 227

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. 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!

Upvotes: 20

Views: 275758

Answers (4)

Chris Sim
Chris Sim

Reputation: 4132

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

Upvotes: 6

rajeesh
rajeesh

Reputation: 634

new SecondForm().setVisible(true);

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

Upvotes: 8

avdhesh dubey
avdhesh dubey

Reputation: 11

JFrame.setVisible(true);

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

Upvotes: 1

Gokul E
Gokul E

Reputation: 1386

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

Upvotes: 24

Related Questions