FileDocCategorySizeDatePackage
FieldEdit.javaAPI DocExample1327Sun Dec 27 15:20:28 GMT 1998None

FieldEdit

public class FieldEdit extends Applet
FieldEdit - an Applet to validate data as it's being entered. Not very general: a 52 minute hack to show the mechanics of editing. Does try to leave the cursor in exactly the right position.
author
Ian Darwin, ian@darwinsys.com
author
Bjorn Gudehus, gothic@celestica.com

Fields Summary
private Label
myLabel
The label to display the type of thing we're editing
private TextField
textField
The textfield to enter
Constructors Summary
Methods Summary
public voidinit()
Init() is an Applet method used to set up the GUI and listeners

		add(myLabel = new Label("Hex:"));
		add(textField = new TextField(10));
		textField.addTextListener(new TextListener() {
			public void textValueChanged(TextEvent ev) {
				int caret = -1;
				TextField tf = FieldEdit.this.textField;
				String s = tf.getText();
				StringBuffer sb = new StringBuffer();
				System.out.println("Text->" + s);
				for (int i=0; i<s.length(); i++) {
					char c = s.charAt(i);
					if (Character.digit(c, 16) >= 0)
						sb.append(c);
					else
						caret = tf.getCaretPosition()-1;
				}
				if (caret >= 0) {
					tf.setText(sb.toString());
					tf.setCaretPosition(caret);
					Toolkit.getDefaultToolkit().beep();
				}
			}
		});