home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JAVA_UTL / HYPERPRO / SRC / PVS / UTILS / DOUBLEFI.JAV < prev    next >
Encoding:
Text File  |  1996-09-14  |  1.6 KB  |  68 lines

  1. package PVS.Utils;
  2.  
  3. import java.awt.*;
  4.  
  5. public class DoubleField extends Panel{
  6.   static public final int TEXTLEN = 6;
  7.   public DoubleR value = null;
  8.   public TextField textField;
  9.  
  10.   public DoubleField(String label, DoubleR value,GridBagLayout layout, int width) {
  11.  
  12.     this.textField = new TextField(width);  
  13.     this.value = value; 
  14.     textField.setText(value.toString());
  15.     
  16.     this.setLayout(layout);
  17.     int x = 0;
  18.     if(label != null)
  19.       WindowUtils.constrain(this,new Label(label),x++,0,1,1,GridBagConstraints.NONE,
  20.                 GridBagConstraints.EAST,1.,1.,5,0,0,0);
  21.     WindowUtils.constrain(this,textField,x,0,1,1,GridBagConstraints.NONE,
  22.               GridBagConstraints.WEST,1.,1.,0,0,0,0);
  23.   }
  24.  
  25.   public DoubleField(String label, DoubleR value,GridBagLayout layout) {
  26.     this(label,value,layout,TEXTLEN);
  27.   }
  28.  
  29.   public DoubleField(String label, DoubleR value) {
  30.     this(label,value,new GridBagLayout());
  31.   }
  32.  
  33.   /**
  34.     assign new value to editable
  35.    */
  36.   public void setValue(double newvalue){
  37.     this.value.value = newvalue;
  38.     updateField();
  39.   }
  40.  
  41.   /**
  42.     set new editable value
  43.    */
  44.   public void setValue(DoubleR newvalue){
  45.     this.value = newvalue;
  46.     updateField();
  47.   }
  48.  
  49.   public void updateField(){
  50.     textField.setText(value.toString()); 
  51.   }
  52.   public void readField(){
  53.     value.value =  (Double.valueOf(textField.getText())).doubleValue();
  54.   }
  55.   public boolean action(Event e,Object what){
  56.     if(e.target == textField){
  57.       readField();
  58.     }
  59.     return false;
  60.   }
  61.   public boolean lostFocus(Event e,Object what) {
  62.     if(e.target == textField){
  63.       readField();
  64.     }
  65.     return false;
  66.   }  
  67. }
  68.