home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap23 / FrameApplet3.java < prev    next >
Text File  |  1996-03-06  |  1KB  |  61 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class FrameApplet3 extends Applet
  5. {
  6.     CustomFrame frame;
  7.     Button button;
  8.  
  9.     public void init()
  10.     {
  11.           frame = new CustomFrame("Custom Frame Window");
  12.           button = new Button("Show Window");
  13.           add(button);
  14.     }
  15.  
  16.     public boolean action(Event evt, Object arg)
  17.     {
  18.         boolean visible = frame.isShowing();
  19.         if (visible)
  20.         {
  21.             frame.hide();
  22.             button.setLabel("Show Window");
  23.         }
  24.         else
  25.         {
  26.             frame.show();
  27.             button.setLabel("Hide Window");
  28.         }
  29.  
  30.         return true;
  31.     }
  32. }
  33.  
  34. class CustomFrame extends Frame
  35. {
  36.     Button button;
  37.  
  38.     CustomFrame(String title)
  39.     {
  40.         super(title);
  41.         FlowLayout layout = new FlowLayout();
  42.         setLayout(layout);
  43.         button = new Button("Close Window");
  44.         add(button);
  45.     }
  46.  
  47.     public void paint(Graphics g)
  48.     {
  49.         resize(200, 100);
  50.         g.drawString("This is a custom window.", 30, 50);
  51.     }
  52.  
  53.     public boolean action(Event evt, Object arg)
  54.     {
  55.         if (arg == "Close Window")
  56.             dispose();
  57.  
  58.         return true;
  59.     }
  60. }
  61.