FileDocCategorySizeDatePackage
NumericField.javaAPI DocExample994Sat Apr 23 22:35:42 BST 2005magicbeans

NumericField

public class NumericField extends JTextField

Fields Summary
static int
defaultFieldSize
private double
value
Constructors Summary
public NumericField()


       
		super( defaultFieldSize );
		setInputVerifier( new InputVerifier() {
			public boolean verify( JComponent comp ) {
				JTextField field = (JTextField)comp;
				boolean passed = false;
				try {
					setValue( Double.parseDouble( field.getText() ) );
				} catch ( NumberFormatException e ) {
					comp.getToolkit().beep();
					field.selectAll();
					return false;
				}
				return true;
			}
		} );

		addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				getInputVerifier().verify( NumericField.this );
			}
		} );

	
Methods Summary
public doublegetValue()

		return value;
	
public voidsetValue(double newValue)

		double oldValue = value;
		value = newValue;
		setText( "" + newValue );
		firePropertyChange( "value", oldValue, newValue );