Help me, I'm suffering!
Situation: I have a load() function which loads a bunch
of TextFields with values. There are TextListeners
registered for each of these TextFields. Thus, changing the
text in any of them fires off a TextEvent, even if done
programmatically (by means of setText()).
The problem: I need all the various TextEvents fired off
during the load operation (as a result of using TextField.setText())
to be handled BEFORE the load() function completes. In other words,
load() must hang around waiting for all these events to have been
handled by somehow blocking on a state variable.
Some code:
public class Stupid extends Something implements TextListener
{
TextField lname = new TextField();
TextField fname = new TextField();
public Stupid()
{
lname.setName("LNAME");
fname.setName("FNAME");
lname.addTextListener(this);
fname.addTextListener(this);
load();
}
public void textValueChanged(TextEvent e)
{
System.out.println(paramString() + ": " + e.getSource().toString());
}
public void load()
{
System.out.println("LOADING...");
lname.setText("Quixote");
fname.setText("Don");
System.out.println("LOADED.");
}
}
Some output:
LOADING...
LOADED.
TEXT_VALUE_CHANGED: java.awt.TextField[LNAME,116,142,230x31,invalid,text=Quixote,editable ,selection=0-0]
TEXT_VALUE_CHANGED: java.awt.TextField[FNAME,116,173,230x31,invalid,text=Don,editable,sel ection=0-0]
What I want:
LOADING...
TEXT_VALUE_CHANGED: java.awt.TextField[LNAME,116,142,230x31,invalid,text=Quixote,editable ,selection=0-0]
TEXT_VALUE_CHANGED: java.awt.TextField[FNAME,116,173,230x31,invalid,text=Don,editable,sel ection=0-0]
LOADED.
Any ideas? I'm going mad here!