Java AWT WindowAdapter extend

Description

Java AWT WindowAdapter extend

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class Main {
  JFrame window = new JFrame("java2s.com");
  public Main() {
    window.setBounds(30, 30, 300, 300);//www . j a  va  2 s.  c  o m
    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