home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / WindowCloser.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.3 KB  |  65 lines

  1.  
  2. /**
  3.  * Utility class to catch window close events on a target
  4.  * window and actually dispose the window.
  5.  */
  6.  
  7. package sun.beanbox;
  8.  
  9. import java.awt.*;
  10. import java.awt.event.*;
  11.  
  12. public class WindowCloser implements WindowListener {
  13.  
  14.    /**
  15.     * Create an adaptor to listen for window closing events
  16.     * on the given window and actually perform the close.
  17.     */
  18.  
  19.     public WindowCloser(Window w) {
  20.     this(w, false);
  21.     }
  22.  
  23.    /**
  24.     * Create an adaptor to listen for window closing events
  25.     * on the given window and actually perform the close.
  26.     * If "exitOnClose" is true we do a System.exit on close.
  27.     */
  28.  
  29.     public WindowCloser(Window w, boolean exitOnClose) {
  30.     this.exitOnClose = exitOnClose;
  31.     w.addWindowListener(this);
  32.     }
  33.  
  34.  
  35.     public void windowOpened(WindowEvent e) {
  36.     }
  37.  
  38.     public void windowClosing(WindowEvent e) {
  39.     if (exitOnClose) {
  40.             System.exit(0);
  41.     }
  42.     e.getWindow().dispose();
  43.     }
  44.  
  45.     public void windowClosed(WindowEvent e) {
  46.     if (exitOnClose) {
  47.             System.exit(0);
  48.     }
  49.     }
  50.  
  51.     public void windowIconified(WindowEvent e) {
  52.     }
  53.  
  54.     public void windowDeiconified(WindowEvent e) {
  55.     }
  56.  
  57.     public void windowActivated(WindowEvent e) {
  58.     }
  59.  
  60.     public void windowDeactivated(WindowEvent e) {
  61.     }
  62.  
  63.     private boolean exitOnClose;
  64. }
  65.