home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / pr8adpl7 / fixedframe.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.0 KB  |  57 lines

  1. // FixedFrame.java
  2. // A Frame that is guaranteed to be at least some minimum size, and
  3. // will disappear when closed.
  4. import java.awt.Frame;
  5. import java.awt.Dimension;
  6. import java.awt.Insets;
  7. import java.awt.Event;
  8.  
  9. public class FixedFrame extends Frame
  10. {
  11.     int width, height;
  12.  
  13.     FixedFrame(Dimension s)
  14.     {
  15.     this(s.width, s.height);
  16.     }
  17.  
  18.     FixedFrame(int w, int h)
  19.     {
  20.     width = w; height = h;
  21.     move(200+(int)(Math.random()*50), 200+(int)(Math.random()*50));
  22.     }
  23.  
  24.     FixedFrame()
  25.     {
  26.     this(-1, -1);
  27.     }
  28.  
  29.     void setsize(Dimension s)
  30.     {
  31.     width = s.width; height = s.height;
  32.     }
  33.  
  34.     public Dimension preferredSize()
  35.     {
  36.     Dimension sp = super.preferredSize();
  37.     Insets is = insets();
  38.     return new Dimension(width == -1 ? sp.width : width,
  39.                  (height == -1 ? sp.height : height)+20);
  40.     }
  41.  
  42.     public Dimension minimumSize()
  43.     {
  44.     return preferredSize();
  45.     }
  46.  
  47.     // handleEvent
  48.     // Remove this window if closed. Can be overridden in subclasses
  49.     public boolean handleEvent(Event evt)
  50.     {
  51.     if (evt.id == Event.WINDOW_DESTROY)
  52.         dispose();
  53.     return super.handleEvent(evt);
  54.     }
  55. }
  56.  
  57.