Skip to main content
gamedev.net
🔒 Locked

Exiting in java

Started by LessThanJoe 1 reply 750+ views
Original Post
LessThanJoe
LessThanJoe
YOu''d think this would be simple to find, but I can''t seem to find a function to use to exit the program when using java with swing. anyone want to shine some light?
Zipster
Zipster
Is System.exit(...); what you''re looking for?
LizardCPP
LizardCPP
If you are using java with Swing then Probably you hacve a window of some kind, if you have a class tht inherits from JFrame or have a JFrame somewhere in a class you can do:

// Aggregation
JFrame j = new JFrame();
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Inheritance
public class MyFrame extends JFrame {
public MyFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
and then the window and application will die if you press the litle x in the top right corner of the window.

Otherwise if you got an window or not Zipsters advise allways works System.extit(0);

LizardCPP

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.