Hey there.
At the moment to close a form (like to go back to a previous form) i use this.hide();
But ive read things that some statements "Dont realy close the form, and it still runs or whatever"
Is this the rigt way to close one of my forms?

And also, why when i press the close button on the top right hand corner, it closes my WHOLE program, and not just that form.

Thanx Ruan

Hide keeps your whole form with all its components and other variables live in memory - it just hides it on the screen. If you want to re-open it with the existing data etc still there, hide is appropriate.
If you want to re-open it with its contents/state reset to the original, then you would do better to get rid of the old form rather than hide it, and create a new one when you need it. You can get rid of a form by calling its dispose() method.

For close, check out JFrame's setDefaultCloseOperation method. That defines what to do when the close button is clicked. The default is to hide the window. Mostly you would use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for a main window in a simple application.

Hide keeps your whole form with all its components and other variables live in memory - it just hides it on the screen. If you want to re-open it with the existing data etc still there, hide is appropriate.
If you want to re-open it with its contents/state reset to the original, then you would do better to get rid of the old form rather than hide it, and create a new one when you need it. You can get rid of a form by calling its dispose() method.

For close, check out JFrame's setDefaultCloseOperation method. That defines what to do when the close button is clicked. The default is to hide the window. Mostly you would use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for a main window in a simple application.

Ausm, thank you!

Hey there.
At the moment to close a form (like to go back to a previous form) i use this.hide();
But ive read things that some statements "Dont realy close the form, and it still runs or whatever"
Is this the rigt way to close one of my forms?

And also, why when i press the close button on the top right hand corner, it closes my WHOLE program, and not just that form.

Thanx Ruan

It would also be good to note hide is a deprecated method, so i wouldnt advise using that for any long term code...As of JDK version 1.1, replaced by setVisible(boolean) see here:http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#show%28%29

This question has already been answered. Start a new discussion instead.