Both TextArea and TextField can install a TextListener that catches TextEvents. TextComponents fire TextEvents every time the text of the component changes. This is more or less every time the user hits a key in the component.

The java.awt.event.TextListener interface defines a single method, textValueChanged():

public void textValueChanged(TextEvent te)

You register a TextListener with a TextComponent by calling the component's addTextListener() method. For example,

TextArea password = new TextArea(24)
password.addTextListener(new PasswordChecker());

However, most of the time it's sufficient to just get and set the text as you need it. It's really quite rare that you need to process it character by character.

A TextListener can be removed by calling removeTextListener().

public void removeTextListener(TextListener tl)

Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
Last Modified November 4, 1997