Using Adapter Classes : Window Event « Swing Event « Java Tutorial






An adapter class is a term for a class that implements a listener interface with methods that have no content (Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton Wrox Press 2005)

Using Adapter Classes
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class Sketcher {
  JFrame window = new JFrame("Sketcher");
  public Sketcher() {
    window.setBounds(30, 30, 300, 300);
    window.addWindowListener(new WindowHandler());
    window.setVisible(true);
  }
  class WindowHandler extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
      System.out.println("closing");
      window.dispose(); // Release the window resources
      System.exit(0); // End the application
    }
  }
  public static void main(String[] args) {
    new Sketcher();
  }
}








15.41.Window Event
15.41.1.The event IDs for the WindowEvent class
15.41.2.Making a Window Handle its Own EventsMaking a Window Handle its Own Events
15.41.3.The WindowListener Interface: events reflecting changes in the state of a window
15.41.4.Using WindowListenerUsing WindowListener
15.41.5.Using Adapter ClassesUsing Adapter Classes
15.41.6.Listens for window iconify and deiconify events, so that it can stop the animation when the window isn't visible.Listens for window iconify and deiconify events, so that it can stop the animation when the window isn't visible.
15.41.7.WindowListener, WindowFocusListener, WindowStateListener
15.41.8.extends WindowAdapter
15.41.9.Handle a window closing event
15.41.10.Setting the Initial Focused Component in a Window
15.41.11.int java.awt.event.WindowEvent.WINDOW_OPENED