home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / netscape / applet / ConsoleFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  3.3 KB  |  99 lines

  1. package netscape.applet;
  2.  
  3. import java.awt.Button;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.Frame;
  7. import java.awt.GridBagConstraints;
  8. import java.awt.GridBagLayout;
  9. import java.awt.Insets;
  10. import java.awt.TextArea;
  11. import java.awt.Window;
  12.  
  13. class ConsoleFrame extends Frame {
  14.    Console console;
  15.    TextArea text;
  16.    Button reset;
  17.    Button hide;
  18.  
  19.    ConsoleFrame(Console console) {
  20.       this.console = console;
  21.       ((Frame)this).setTitle("Java Console");
  22.       GridBagLayout gb = new GridBagLayout();
  23.       ((Container)this).setLayout(gb);
  24.       this.text = new TextArea(20, 60);
  25.       this.text.setEditable(false);
  26.       GridBagConstraints c1 = new GridBagConstraints();
  27.       c1.fill = 1;
  28.       c1.weightx = (double)1.0F;
  29.       c1.weighty = (double)1.0F;
  30.       c1.gridwidth = 0;
  31.       gb.setConstraints(this.text, c1);
  32.       ((Container)this).add(this.text);
  33.       HorizontalRule hr = new HorizontalRule();
  34.       GridBagConstraints c2 = new GridBagConstraints();
  35.       c2.fill = 2;
  36.       c2.weightx = (double)1.0F;
  37.       c2.insets = new Insets(1, 1, 0, 0);
  38.       c2.gridwidth = 0;
  39.       gb.setConstraints(hr, c2);
  40.       ((Container)this).add(hr);
  41.       this.reset = new Button("Clear");
  42.       GridBagConstraints c3 = new GridBagConstraints();
  43.       c3.insets = new Insets(4, 0, 2, 4);
  44.       c3.anchor = 13;
  45.       gb.setConstraints(this.reset, c3);
  46.       ((Container)this).add(this.reset);
  47.       this.hide = new Button("Close");
  48.       GridBagConstraints c4 = new GridBagConstraints();
  49.       c4.insets = new Insets(4, 0, 2, 4);
  50.       c4.anchor = 13;
  51.       gb.setConstraints(this.hide, c4);
  52.       ((Container)this).add(this.hide);
  53.       ((Window)this).pack();
  54.    }
  55.  
  56.    public boolean handleEvent(Event evt) {
  57.       if (evt.id != 201 && (evt.target != this.hide || evt.id != 1001)) {
  58.          if (evt.target == this.reset && evt.id == 1001) {
  59.             this.console.reset();
  60.             return true;
  61.          } else {
  62.             return super.handleEvent(evt);
  63.          }
  64.       } else {
  65.          this.console.hide();
  66.          return true;
  67.       }
  68.    }
  69.  
  70.    public boolean keyDown(Event evt, int key) {
  71.       if (key >= 48 && key <= 57) {
  72.          MozillaAppletContext.debug = key - 48;
  73.          System.err.println("# Applet debug level set to " + MozillaAppletContext.debug);
  74.          return true;
  75.       } else if (key != 100 && key != 68) {
  76.          if (key != 103 && key != 71) {
  77.             if (key != 102 && key != 70) {
  78.                return super.keyDown(evt, key);
  79.             } else {
  80.                System.err.println("# Performing finalization...");
  81.                System.runFinalization();
  82.                return true;
  83.             }
  84.          } else {
  85.             System.err.println("# Performing a garbage collection...");
  86.             System.gc();
  87.             return true;
  88.          }
  89.       } else {
  90.          MozillaAppletContext.dumpState(System.err);
  91.          return true;
  92.       }
  93.    }
  94.  
  95.    void reset() {
  96.       this.text.setText("");
  97.    }
  98. }
  99.