| | |
GUI Window - Exit Button?
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
Is there a cleaner way to close out of a GUI window in Java then just clicing the X in the upper right hand corner? When I do this I get a NullPointerException error.
Is there a way to put an "Exit" button in a GUI window so that the window (program) closes much cleaner?
I'm aware of the system.exit command, but that's not what I'm looking for.
Any suggestions?
Is there a way to put an "Exit" button in a GUI window so that the window (program) closes much cleaner?
I'm aware of the system.exit command, but that's not what I'm looking for.
Any suggestions?
I think System.exit is the quickest way shutdown apps in java. I usually disble the X button of the GUI and provide an exit menu for exiting.
As to specifically see javax.swing.JMenu API to insert menus in your app ... and to disable the X button :
see javax.swing.JFrame --> setDefaultCloseOperation(int )
see javax.swing.JFrame --> setDefaultCloseOperation(int )
•
•
•
•
setDefaultCloseOperation
public void setDefaultCloseOperation(int operation)Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:
DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.
The value is set to HIDE_ON_CLOSE by default.
If I can teach one person to learn to find their own answers I'll have helped one person...
If I regurgitate code for everyone who wants some I've helped noone as they'll still not know how to find their own answers and will forever (or more likely until they end up in the unemployment line) come here for more and more.
If I regurgitate code for everyone who wants some I've helped noone as they'll still not know how to find their own answers and will forever (or more likely until they end up in the unemployment line) come here for more and more.
![]() |
Other Threads in the Java Forum
- Previous Thread: How to load binary content of a .class file?
- Next Thread: How to make a thread never be terminated?
| Thread Tools | Search this Thread |
2dgraphics @param account affinetransform android api apple applet application arc arguments array automation banking binary binarytree bluetooth chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image inheritance integer j2me java java.xls javadesktopapplications javaprojects jlabel jni jpanel julia keytool keyword linux list macintosh map method methods midlethttpconnection mobile monitoring netbeans nullpointerexception object open-source pong problem producer program project projectideas property reference replaysolutions ria rim scanner server set size sms sourcelabs splash sql swing terminal threads transforms tree ui unicode validation web windows






