Window Events Example

For example, windows don't close on their own. You have to explicitly close them. The following subclass of Frame puts up a window that responds to efforts to close it by calling setVisible(false) and dispose().

import java.awt.*;
import java.awt.event.*;


public class ClosableFrame extends Frame implements WindowListener {

  public ClosableFrame() {
    this.addWindowListener(this);
  }
  
  public ClosableFrame(String s) {
    super(s);
    this.addWindowListener(this);
  }
  
  public void windowClosing(WindowEvent e) {
    this.setVisible(false);
    this.dispose();
  }
  
  public void windowOpened(WindowEvent e) {}  
  public void windowClosed(WindowEvent e) {}
  public void windowIconified(WindowEvent e) {}
  public void windowDeiconified(WindowEvent e) {}
  public void windowActivated(WindowEvent e) {}
  public void windowDeactivated(WindowEvent e) {}

}

Previous | Next | Top
Last Modified June 30, 1998
Copyright 1997, 1998 Elliotte Rusty Harold
elharo@metalab.unc.edu