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

  1. import java.applet.*;
  2. import java.awt.*;
  3. import WorkPanel;
  4.  
  5. class SetSizeFrame extends Frame
  6. {
  7.     WorkPanel target;
  8.     Applet applet;
  9.     TextField tfWidth, tfHeight, tfComment;
  10.  
  11.     public SetSizeFrame(WorkPanel target, Applet applet)
  12.     {
  13.         super("Set Chart Size");
  14.  
  15.         this.target = target;
  16.         this.applet = applet;
  17.         setLayout(new FlowLayout());
  18.  
  19.         add(new Label("Chart Width : "));
  20.         add((tfWidth =new TextField(4)));
  21.         add(new Label("Chart Height : "));
  22.         add((tfHeight =new TextField(4)));
  23.         add(new Label("Comment : "));
  24.         add((tfComment =new TextField(20)));
  25.         add(new Button("OK"));
  26.         add(new Button("Cancel"));
  27.     }
  28.  
  29.     public boolean keyDown(Event e, int key)
  30.     {
  31.  
  32.         if ( (e.target == tfWidth || e.target == tfHeight) && 
  33.              !(( (Character.isDigit((char)key) && (char)key != '.') ||
  34.                 key == e.LEFT || key == e.RIGHT || key == e.HOME || key == e.END || 
  35.                (char) key == '\b'|| key == 127 ))) //**** 127 is Delete key
  36.             return true;
  37.  
  38.         return super.keyDown(e, key);
  39.     }
  40.     public boolean action(Event e, Object what)
  41.     {
  42.         if (e.target instanceof Button)
  43.         {
  44.             if (e.arg == "OK")
  45.             {
  46.                 int wid = 0, hig = 0;
  47.  
  48.                 try    
  49.                     wid = Integer.parseInt(tfWidth.getText());
  50.                 catch (NumberFormatException nfe1)
  51.                     return true;
  52.                 
  53.                 try
  54.                     hig  = Integer.parseInt(tfHeight.getText());
  55.                 catch (NumberFormatException nfe2)
  56.                     return true;
  57.  
  58.                 target.setSize(wid, hig, tfComment.getText());
  59.             }
  60.             dispose();
  61.             applet.enable();
  62.         }
  63.         return super.action(e, what);
  64.     }
  65. }
  66.