Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2179

confused about the sequen

From "Ray Ma" <ray.ma@THRWHITE.remove-dii-this>
Subject confused about the sequen
Message-ID <1186005594.700709.257210@j4g2000prf.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:37 +0000
Organization TDS.net

Show all headers | View raw


  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

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar | Unroll thread


Thread

confused about the sequen "Ray Ma" <ray.ma@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: confused about the se "Laird Nelson" <laird.nelson@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: confused about the se "Tom Hawtin" <tom.hawtin@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: confused about the se "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000

csiph-web