Java Source Code: de.pxlab.awtx.CloseableFrame


   1: 
   2: package de.pxlab.awtx;
   3: 
   4: import java.applet.Applet;
   5: import java.awt.*;
   6: import java.awt.event.*;
   7: import java.awt.image.ImageProducer;
   8: import java.io.IOException;
   9: import java.net.URL;
  10: 
  11: /** This is a frame which has an active window closing button, may
  12:     have an icon, and knows whether it has an applet or an application
  13:     as its parent.  The frame's layout manager is BorderLayout.
  14: 
  15:     @author H. Irtel
  16:     @version 0.3.0 */
  17: 
  18: /*
  19:   08/11/01 
  20: */
  21: 
  22:	  public class CloseableFrame extends DecoratedFrame {
  23:
  24:    /** Create a new closeable frame. 
  25:    @param title the title of the frame,
  26:    @param parent if this frame is instantiated by an applet then
  27:    it should send its reference to the frame.
  28:    @param icon the frame's icon.
  29:    */
  30:	      public CloseableFrame(String title, Applet parent, Image icon) {
  31:
  32:    super(title, parent, icon);
  33:
  34:	      addWindowListener(new WindowAdapter() {
  35:	          public void windowClosing(WindowEvent evt) {
  36:	              if (isApplication()) {
  37:            evt.getWindow().dispose();
  38:            System.exit(0);
  39:            } else {
  40:            CloseableFrame.this.parent.stop();
  41:            }
  42:        }
  43:        }
  44:    );
  45:    }
  46:
  47:
  48:    /** Create a new closeable frame which has an application as its
  49:    parent.
  50:    @param title the title of the frame.  */
  51:	      public CloseableFrame(String title) {
  52:    this(title, null, null);
  53:    }
  54:
  55:
  56:    /** Create a new closeable frame which has an application as its
  57:    parent and uses the given icon file.
  58:    @param title the title of the frame,
  59:    @param icon the image
  60:    for this frame's icon.  */
  61:	      public CloseableFrame(String title, Image icon) {
  62:    this(title, null, icon);
  63:    }
  64:}