Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/meowers/cide/edcide/util/ValidatedInteger.java


1   /*
2    * ValidatedInteger.java
3    *
4    * Created on February 2, 2002, 4:54 PM
5    */
6   
7   package org.meowers.cide.edcide.util;
8   
9   import javax.swing.*;
10  
11  /**
12   *
13   * @author  praxis
14   * @version 
15   */
16  public class ValidatedInteger extends ValidatedDataType {
17  
18      int i;
19      
20      /** Creates new ValidatedInteger */
21      public ValidatedInteger() {
22      }
23  
24      public ValidatedInteger(int i, boolean valid) {
25          this.i = i;
26          this.valid = valid;
27      }
28      
29      public ValidatedInteger(JTextField jtf, int min, int max, String name) {
30          int myint = 0;
31          boolean valid = true;
32          
33          try {
34              myint = (new Integer(jtf.getText())).intValue();
35          } catch (NumberFormatException e) {
36              System.out.println("Not valid because of exception." + e);
37              valid = false;
38          }
39          if (valid == false || myint < min || myint > max) {
40             int ans = JOptionPane.showConfirmDialog(jtf.getTopLevelAncestor(), 
41                  name + " should be an integer between " + min + " and " + max,
42                  "Error", JOptionPane.OK_OPTION,
43                  JOptionPane.ERROR_MESSAGE);
44             valid = false;
45          }
46          
47          i = myint;
48          this.valid = valid;
49      }
50          
51      public int getValue() {
52          return (i);
53      }
54      
55      
56  }