Class JTextTools

java.lang.Object
  |
  +--JTextTools

public class JTextTools
extends java.lang.Object

A number of useful methods for dealing with JTextFields.


Constructor Summary
JTextTools()
           
 
Method Summary
static void dealWithInvalidValue(javax.swing.JTextField jTxt)
          Method for dealing with an invalid value in a JTextField.
static double getDouble(javax.swing.JTextField jTxt, javax.swing.JTextArea jTxtArea, java.lang.String errMessage)
          Method for getting a double value from a JTextField.
static int getInt(javax.swing.JTextField jTxt, javax.swing.JTextArea jTxtArea, java.lang.String errMessage)
          Method for getting an int value from a JTextField.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTextTools

public JTextTools()
Method Detail

dealWithInvalidValue

public static void dealWithInvalidValue(javax.swing.JTextField jTxt)
Method for dealing with an invalid value in a JTextField. The method clears the text field and sets the focus on it, after which it throws an IllegalArgumentException.

Parameters:
jTxt - the JTextField
Throws:
java.lang.IllegalArgumentException - always thrown

getDouble

public static double getDouble(javax.swing.JTextField jTxt,
                               javax.swing.JTextArea jTxtArea,
                               java.lang.String errMessage)
Method for getting a double value from a JTextField. If the value is not valid an error message is appended to the text area and then dealWithInvalidValue is called resulting in an IllegalArgumentException being thrown. Otherwise the value read from the text field is returned.

Parameters:
jTxt - the JTextField
jTxtArea - the JTextArea
errMessage - the error message to be appended to the text area
Throws:
java.lang.IllegalArgumentException - if text field contains an invalid value

getInt

public static int getInt(javax.swing.JTextField jTxt,
                         javax.swing.JTextArea jTxtArea,
                         java.lang.String errMessage)
Method for getting an int value from a JTextField. If the value is not valid then dealWithInvalidValue is called resulting in an IllegalArgumentException being thrown. Otherwise the value read from the text field is returned.

Parameters:
jTxt - the JTextField
jTxtArea - the JTextArea
errMessage - the error message to be appended to the text area
Throws:
java.lang.IllegalArgumentException - if text field contains an invalid value