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
Asked
Active
Viewed 9,033 times
1 Answers
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
-
1In 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