TextArea
and TextField
can install
a TextListener
that catches TextEvent
s. TextComponent
s fire TextEvent
s 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 abstract 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)