How do I close a JFrame application?
Category: javax.swing, viewed: 905 time(s).
Closing a JFrame application can be done by setting the default close operation of the frame. There are some defined constant for the default operation. These constant includes EXIT_ON_CLOSE, HIDE_ON_CLOSE, DO_NOTHING_ON_CLOSE and DISPOSE_ON_CLOSE.
To exit an aplication we can set it to EXIT_ON_CLOSE, this option will call the System.exit() method when user initiate a close operation on the frame.
package org.kodejava.example.swing; import javax.swing.JFrame; public class MainFrameClose extends JFrame { public static void main(String[] args) { MainFrameClose frame = new MainFrameClose(); frame.setSize(100, 100); // // Be defining the default close operation of a JFrame to EXIT_ON_CLOSE // the application will be exited by calling System.exit() when user // initiate a close event on the frame. // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } |
Can't find what you are looking for? Join our FORUMS and ask some questions!
Related Examples
- How do I right justified JTextField contents?
- How do I format JLabel using HTML?
- How do I display an image in JButton?
- How do I use JFormattedTextField to format user input?
- How do I handle mouse button click event?
- How do I handle mouse wheel event?
- How do I handle mouse motion event?
- How do I handle mouse event in swing?
- How do I get the system look and feel?
- How do I set the look and feel for swing application?