1

i wan to close the particular classname.java window alone.

I am developing a GUI using netbeans. I created a main class and defined a button , when clicked will load new classname().setVisible(true);

this classname.java contains a frame with components to get the input

now when i use System.exit(); in classname.java all the windows are closed

i wan to close the particular classname.java window alone. how can i do so ?

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   System.exit(0); // TODO add your handling code here:
}
radish
  • 115
  • 1
  • 4
  • 13

4 Answers4

2

USE DISPOSE_ON_CLOSE

JFrame f = JFrame();
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)`
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
1

If you just want to hide it use

setVisible(false);

Or to dispose use

dispose(); 
Phil
  • 463
  • 3
  • 9
0

Make sure you keep a reference to the classname instance you created, and call either setVisible(false) or dispose() on it.

Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80
0

When you do that,it will close all the windows opened, it means that the app will be ended. I think you should use this method: windowClosing(). You can get more information about this, here:link

I hope that is helpful to you. Regards, Gil

Gil Mota
  • 79
  • 1
  • 11