Be a Supporter!

To System.exit or not System.exit

  • 451 Views
  • 8 Replies
New Topic Respond to this Topic
Myke3D
Myke3D
  • Member since: Apr. 20, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
To System.exit or not System.exit 2006-11-08 11:56:42 Reply

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
Response to To System.exit or not System.exit 2006-11-08 11:57:59 Reply

I mean no methods. None.

StarCleaver
StarCleaver
  • Member since: Jan. 3, 2003
  • Offline.
Forum Stats
Member
Level 29
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 13:48:33 Reply

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

BBS Signature
amaterasu
amaterasu
  • Member since: Mar. 7, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 13:49:54 Reply

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

BBS Signature
amaterasu
amaterasu
  • Member since: Mar. 7, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 13:52:36 Reply

Just to clarify, add that line to the method where you initialize the frame, preferably before you set it to visible.


beep

BBS Signature
StarCleaver
StarCleaver
  • Member since: Jan. 3, 2003
  • Offline.
Forum Stats
Member
Level 29
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 14:26:32 Reply

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

BBS Signature
amaterasu
amaterasu
  • Member since: Mar. 7, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 14:34:05 Reply

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,

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();

Of course it does, but the topic starter wanted to know how to exit a JFrame without using System.exit().


beep

BBS Signature
StarCleaver
StarCleaver
  • Member since: Jan. 3, 2003
  • Offline.
Forum Stats
Member
Level 29
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 14:57:54 Reply

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

BBS Signature
amaterasu
amaterasu
  • Member since: Mar. 7, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to To System.exit or not System.exit 2006-11-08 17:15:42 Reply

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

BBS Signature