Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. package rene.gui;
  2.  
  3.  
  4. /**
  5. A TextField, which holds an integer number with minimal
  6. and maximal range.
  7. */
  8.  
  9. public class IntField extends TextFieldAction
  10. {       public IntField (DoActionListener l, String name, int v)
  11.         {       super(l,name,""+v);
  12.         }
  13.         public IntField (DoActionListener l, String name, int v, int cols)
  14.         {       super(l,name,""+v,cols);
  15.         }
  16.         public int value ()
  17.         {       try
  18.                 {       return Integer.parseInt(getText());
  19.                 }
  20.                 catch (NumberFormatException e)
  21.                 {       setText(""+0);
  22.                         return 0;
  23.                 }
  24.         }
  25.         public int value (int min, int max)
  26.         {       int n;
  27.                 try
  28.                 {       n=Integer.parseInt(getText());
  29.                 }
  30.                 catch (NumberFormatException e)
  31.                 {       setText(""+min);
  32.                         return min;
  33.                 }
  34.                 if (n<min) { n=min; setText(""+min); }
  35.                 if (n>max) { n=max; setText(""+max); }
  36.                 return n;
  37.         }
  38.         public void set (int v)
  39.         {       setText(""+v);
  40.         }
  41.         public boolean valid ()
  42.         {       try
  43.                 {       Integer.parseInt(getText());
  44.                 }
  45.                 catch (NumberFormatException e)
  46.                 {       return false;
  47.                 }
  48.                 return true;
  49.         }
  50. }
  51.  
  52.  
  53.