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();
}
}
});