1 30 31 package rcm.awt; 32 import java.awt.*; 33 import java.awt.event.*; 34 35 public class ClosableFrame extends Frame 36 { 37 boolean hideWhenClosed = false; 38 39 public ClosableFrame () { 40 super (); 41 addWindowListener (new CloseHandler ()); 42 } 43 44 public ClosableFrame (String title) { 45 super (title); 46 addWindowListener (new CloseHandler ()); 47 } 48 49 public ClosableFrame (boolean hideWhenClosed) { 50 this(); 51 this.hideWhenClosed = hideWhenClosed; 52 } 53 54 public ClosableFrame (String title, boolean hideWhenClosed) { 55 this (title); 56 this.hideWhenClosed = hideWhenClosed; 57 } 58 59 public void close () { 60 if (hideWhenClosed) 61 setVisible (false); 62 else 63 dispose (); 64 } 65 66 class CloseHandler extends WindowAdapter { 67 public void windowClosing (WindowEvent event) { 68 close (); 69 } 70 } 71 } 72 | Popular Tags |