confused about the sequen
To: comp.lang.java.gui
Hi, all,
I have a question about execution order of event listeners when an
event occur and two or more listeners are registered for that event.
For example, I have a panel class that contains a textfield for enter
number and a "plus", a "minus" button for increase/decrease the
number. Inside this class, I add document listener for the textfield
changes.
class NumberPanel{
JTextField numberTxFld = new JTextField();
JButton upButton, downButton;
int value;
...
numberTxFld.getDocument.addDocumentListener(new
DocumentListener(){
....
public void insertUpdate(){
setValue();
}
public void removeUpdate(){
setValue();
}
});
...
private void setValue(){
this.value = Interger.parseInt(numberTxFld.getText());
}
}
I also have another GUI component "CalculationPanel" that include
this numberPanel. The "CalculationPanel" needs to communicate with
other GUI component about the changes of the "value". So I also add
another document listener for the numberTxFld in "CalculationPanel". I
can't add this in the NumberPanel because the NumberPanel has no
reference/knowledge of the other GUI component.
class CalculationPanel {
NumberPanel numberPan = new NumberPanel();
JTextField calculaterTxFld = numberPan.numberTxFld;
OtherComponent otherComp = new OtherComponent();
......
calculaterTxFld.getDocument().addDocumentListener(new
DocumentListener(){
....
public void insertUpdate(){
notifyOtherComponent();
}
public void removeUpdate(){
notifyOtherComponent();
}
});
notifyOtherComponent(){
otherComp.setNumberValue (calculaterTxFld.value);
}
}
In the Main() method, the CalculationPanel is added to the root
Frame. When I input to the textfield, I notice that the listener I
wrote in the "CalculationPanel" is executed first, then the listener
in "NumberPanel". I wonder why and how can I control their order of
execution?
Thanks
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24