20

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

4 Answers 4

25

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..
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

It's better to use this.dispose() instead making it invisible as it will be still running without any use.
Yea Thats correct. But i thought that while the Form is dispose it may return to Main Function without showing the FrmMain.. OOPS... I thought the Code will be Stopped then...
Great thought :) The code won't be stoped until executing all statements inside the actionPerformed method.
8
new SecondForm().setVisible(true);

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

Comments

6

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

Comments

1
JFrame.setVisible(true);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.