FileDocCategorySizeDatePackage
WholeNumberField.javaAPI DocExample1898Tue Dec 12 18:59:20 GMT 2000None

WholeNumberField

public class WholeNumberField extends JTextField

Fields Summary
private Toolkit
toolkit
private NumberFormat
integerFormatter
Constructors Summary
public WholeNumberField(int value, int columns)

        super(columns);
        toolkit = Toolkit.getDefaultToolkit();
        integerFormatter = NumberFormat.getNumberInstance(Locale.US);
        integerFormatter.setParseIntegerOnly(true);
        setValue(value);
    
Methods Summary
protected javax.swing.text.DocumentcreateDefaultModel()

        return new WholeNumberDocument();
    
public intgetValue()

        int retVal = 0;
        try {
            retVal = integerFormatter.parse(getText()).intValue();
        } catch (ParseException e) {
            // This should never happen because insertString allows
            // only properly formatted data to get in the field.
            toolkit.beep();
        }
        return retVal;
    
public voidsetValue(int value)

        setText(integerFormatter.format(value));