Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 223
Ultrabyte Avatar asked Jul 14 '13 06:07

Ultrabyte


People also ask

How do I open a JFrame in another JFrame?

How to do that? You can't put one JFrame inside another. Change your design so that the Game window content is on a JPanel and the Menu is on another JPanel . This way you can deploy them to where ever you want...

How do I open a JFrame in Netbeans?

In the Projects window, right-click the ContactEditor node and choose New > JFrame Form. Alternatively, you can find a JFrame form by choosing New > Other > Swing GUI Forms > JFrame Form.

How do you link two frames in java?

Just create another class, let us say FrameMananger, then use the singleton pattern to manage them. Then in any class, you can use FrameManager. getFrame1() to get the frame1, same as the frame2. You can add logic judgement inside, like dynamically dispose some frame or only create them when needed.


2 Answers

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..
    }
});
like image 159
Gokul E Avatar answered Oct 11 '22 13:10

Gokul E


new SecondForm().setVisible(true);

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

like image 34
rajeesh Avatar answered Oct 11 '22 14:10

rajeesh