|
How to use WindowListener for closing JFrames |
|
|
This Java Swing tip illustrates a method of using WindowListener for closing
JFrames. This code snippet may be used in any application where it is
required to exit from the application when the frame is closed.
import javax.swing.JFrame;
import java.awt.event.*;
public class FrameClose2 {
public static void main(String[] args) {
JFrame mainFrame = new JFrame();
// Exit app when frame is closed.
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
});
mainFrame.setSize(320, 240);
mainFrame.setVisible(true);
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.