home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / InputField.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-06  |  1.9 KB  |  95 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4.  
  5. class InputField {
  6.    int maxchars = 50;
  7.    int cursorPos;
  8.    Applet app;
  9.    String sval;
  10.    char[] buffer;
  11.    int nChars;
  12.    int width;
  13.    int height;
  14.    Color bgColor;
  15.    Color fgColor;
  16.  
  17.    public InputField(String var1, Applet var2, int var3, int var4, Color var5, Color var6) {
  18.       this.width = var3;
  19.       this.height = var4;
  20.       this.bgColor = var5;
  21.       this.fgColor = var6;
  22.       this.app = var2;
  23.       this.buffer = new char[this.maxchars];
  24.       this.nChars = 0;
  25.       if (var1 != null) {
  26.          var1.getChars(0, var1.length(), this.buffer, 0);
  27.          this.nChars = var1.length();
  28.       }
  29.  
  30.       this.sval = var1;
  31.    }
  32.  
  33.    public void setText(String var1) {
  34.       for(int var2 = 0; var2 < this.maxchars; ++var2) {
  35.          this.buffer[var2] = 0;
  36.       }
  37.  
  38.       this.sval = new String(var1);
  39.       if (var1 == null) {
  40.          this.sval = "";
  41.          this.nChars = 0;
  42.          this.buffer[0] = 0;
  43.       } else {
  44.          this.sval.getChars(0, this.sval.length(), this.buffer, 0);
  45.          this.nChars = var1.length();
  46.          this.sval = new String(this.buffer);
  47.       }
  48.    }
  49.  
  50.    public String getValue() {
  51.       return this.sval;
  52.    }
  53.  
  54.    public void paint(Graphics var1, int var2, int var3) {
  55.       var1.setColor(this.bgColor);
  56.       var1.fillRect(var2, var3, this.width, this.height);
  57.       if (this.sval != null) {
  58.          var1.setColor(this.fgColor);
  59.          var1.drawString(this.sval, var2, var3 + this.height / 2 + 3);
  60.       }
  61.  
  62.    }
  63.  
  64.    public void mouseUp(int var1, int var2) {
  65.    }
  66.  
  67.    public void keyDown(int var1) {
  68.       if (this.nChars < this.maxchars) {
  69.          switch (var1) {
  70.             case 8:
  71.                --this.nChars;
  72.                if (this.nChars < 0) {
  73.                   this.nChars = 0;
  74.                }
  75.  
  76.                this.buffer[this.nChars] = 0;
  77.                this.sval = new String(new String(this.buffer));
  78.                break;
  79.             case 9:
  80.             default:
  81.                this.buffer[this.nChars++] = (char)var1;
  82.                this.sval = new String(new String(this.buffer));
  83.                break;
  84.             case 10:
  85.                this.selected();
  86.          }
  87.       }
  88.  
  89.       this.app.repaint();
  90.    }
  91.  
  92.    public void selected() {
  93.    }
  94. }
  95.