1

i am working in JAVA GUI project with netbeans ,, I just created Jframe and put a button on it ,, I created also another JFrame and added many labels I am asking how can the second JFrame appears when i click on the button in the first JFrame

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user1655078
  • 21
  • 1
  • 3
  • 2
    You may also wish to consider [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice) – MadProgrammer Sep 02 '13 at 09:46

1 Answers1

4
button.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        new SecondFrame().setVisible(true);
        FirstFrame.this.dispose(); // if you want the first frame to close
    }

Check out How to Write an Action Listener for more information.

Gabriel Negut
  • 13,860
  • 4
  • 38
  • 45
  • In addtion, if you just want to hide the first frame, use `firstFrame.setVisible(false)`. – BlackBox Sep 02 '13 at 09:46
  • well ,, but when i closed the new popup window ,, the all app closed .. how can i keep the first frame working ??? – user1655078 Sep 02 '13 at 09:48
  • 1
    In the second frame add a `WindowAdapter` and override `windowClosing` to reopen the first frame. Look [here (the Oracle docs)](http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html) for details. – Gabriel Negut Sep 02 '13 at 10:59