Share this page 

Close a FrameTag(s): AWT


[JDK1.0.2]
public boolean handleEvent(Event evt) {
  if (evt.id == Event.WINDOW_DESTROY) {
     System.exit(0);
     return true;
     }
  return super.handleEvent(evt);
}
[JDK1.1 Method 1]
public aFrame extends Frame implements WindowListener {
   public aFrame(){
     addWindowListener( this );
     }
   public void windowActivated(WindowEvent e){}
   public void windowDeactivated(WindowEvent e){}
   public void windowOpened(WindowEvent e){}
   public void windowClosing(WindowEvent e){ System.exit(0); }
   public void windowClosed(WindowEvent e){}
   public void windowIconified(WindowEvent e) {}
   public void windowDeiconified(WindowEvent e) {}
}
[JDK1.1 Method 2]
public class aFrame extends Frame {
   public aFrame(){
      addWindowListener( new Terminate() );
      }
   }

class Terminate extends WindowAdapter{
  public void windowClosing(WindowEvent e){
    System.exit(0);
    }
}
[JDK1.1 Method 3]
public class aFrame extends Frame {
  public aFrame() {
    addWindowListener
      (new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
             System.exit(0);
             }
          }
      );
    }
}

For a Dialog or a Window, a System.exit(0) may not be appropriate, call the dispose() method instead.

class SimplePopUp extends Dialog    {
    SimplePopUp() {
      super(new Frame(), "simple popup");
      this.addWindowListener
       (new WindowAdapter() {
           public void windowClosing(WindowEvent e) {
              e.getWindow().dispose();
              }
           }
       );
}