To System.exit or not System.exit
- Myke3D
-
Myke3D
- Member since: Apr. 20, 2006
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
How can i close a jframe without System.exit? I try but now methods come up.
- Myke3D
-
Myke3D
- Member since: Apr. 20, 2006
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
- StarCleaver
-
StarCleaver
- Member since: Jan. 3, 2003
- Offline.
-
- Forum Stats
- Member
- Level 29
- Blank Slate
Well, you can set the default close operation for the JFrame to DISPOSE_ON_CLOSE or you can use myJFrame.dispose() where myJFrame is your JFrame
I could surely die
If I only had some pie
Club-a-Club Club, son
- amaterasu
-
amaterasu
- Member since: Mar. 7, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
If you are just closing the JFrame with the exit button on the top right corner,
If your class is just extending JFrame, add "this.setDefaultCloseOperation(EXIT_ON_CLOSE) ;
If the JFrame is an instance variable in your class, add "<variablename>.setDefaultCloseOperation(JFra me.EXIT_ON_CLOSE);
beep
- amaterasu
-
amaterasu
- Member since: Mar. 7, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Just to clarify, add that line to the method where you initialize the frame, preferably before you set it to visible.
beep
- StarCleaver
-
StarCleaver
- Member since: Jan. 3, 2003
- Offline.
-
- Forum Stats
- Member
- Level 29
- Blank Slate
At 11/8/06 01:49 PM, amaterasu wrote: If you are just closing the JFrame with the exit button on the top right corner,
If your class is just extending JFrame, add "this.setDefaultCloseOperation(EXIT_ON_CLOSE) ;
If the JFrame is an instance variable in your class, add "<variablename>.setDefaultCloseOperation(JFra me.EXIT_ON_CLOSE);
That will do the same thing as System.exit();
I could surely die
If I only had some pie
Club-a-Club Club, son
- amaterasu
-
amaterasu
- Member since: Mar. 7, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 11/8/06 02:26 PM, StarCleaver wrote:At 11/8/06 01:49 PM, amaterasu wrote: If you are just closing the JFrame with the exit button on the top right corner,That will do the same thing as System.exit();
If your class is just extending JFrame, add "this.setDefaultCloseOperation(EXIT_ON_CLOSE) ;
If the JFrame is an instance variable in your class, add "<variablename>.setDefaultCloseOperation(JFra me.EXIT_ON_CLOSE);
Of course it does, but the topic starter wanted to know how to exit a JFrame without using System.exit().
beep
- StarCleaver
-
StarCleaver
- Member since: Jan. 3, 2003
- Offline.
-
- Forum Stats
- Member
- Level 29
- Blank Slate
At 11/8/06 02:34 PM, amaterasu wrote: Of course it does, but the topic starter wanted to know how to exit a JFrame without using System.exit().
He wanted to know how to close a JFrame, much difference from exiting the application. Unless you are better at reading between the lines and interpreting what the author really means, I believe he just wants to close a JFrame, not exit the application.
I could surely die
If I only had some pie
Club-a-Club Club, son
- amaterasu
-
amaterasu
- Member since: Mar. 7, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 11/8/06 02:57 PM, StarCleaver wrote: He wanted to know how to close a JFrame, much difference from exiting the application. Unless you are better at reading between the lines and interpreting what the author really means, I believe he just wants to close a JFrame, not exit the application.
That was a bad assumption on my part.
beep

