Java AWT WindowAdapter extend to handle window event

Description

Java AWT WindowAdapter extend to handle window event

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class Main {
  JFrame window = new JFrame("Sketcher");
  public Main() {
    window.setBounds(30, 30, 300, 300);//from w  w w. j a va2  s.c  om
    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 Main();
  }
}



PreviousNext

Related