Demonstrating the WindowListener with a WindowAdapter

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
public class WindowAdapterTest {
public static void main(String args[]) {
JFrame frame = new JFrame("Window Listener");
WindowListener listener = new WindowAdapter() {
public void windowClosing(WindowEvent w) {
System.exit(0);
}
};
frame.addWindowListener(listener);
frame.setSize(300, 300);
frame.show();
}
}
Related examples in the same category