/** * a special type of text field for handling integers * * @author Mr J * @version 20040220 */ public class IntegerTextField extends java.awt.TextField { // we don't actually need any extra data members for this class // the constructors can be inherited from the superclass public IntegerTextField(int n) { super(n); } public IntegerTextField(String s) { super(s); } /** * Method to return status of the TextField * * @return true if the TextField has no text in it */ public boolean isEmpty() { // Get the String in the field and test it for length return (super.getText().length() == 0); } /** * Method to return contents of the field as an int * @return the integer */ public int getInteger() { return Integer.parseInt(super.getText().trim()); } }