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


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

how to add listener to li

From "Ray Ma" <ray.ma@THRWHITE.remove-dii-this>
Subject how to add listener to li
Message-ID <1184877904.793570.42730@m37g2000prh.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, there

I have a component class C1 that mainly contains a JTextField and I
hope it can change text value when a button in another component class
C2 is pressed.
If there's no access restriction, I know I can addActionListener to
that button like:

myButton.addActionListener(new ActionListener(){
          public void ActionPerformed(e){
                  String textStr =button.getText() ;
                  myTextField.setText(textStr); //direct access to
myTextField
          }
});

But for security reason, I don't want C1 has direct access to C2's
textField. In stead, I hope to add event listener in C2 for the
textField, so that the textField can get noticed when button press
event occurs. It will then check the button's actionCommand and decide
whether to get the button's text or not.

If I use:
myTextField.addActionListener() it's actually listen to event that
occur on the textField component, not any event occur on other
components.

AbstractButton class has "fireActionPerformed()" method but it's
protected and I don't know how to use.

Is anyone know how to achieve this?

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 | Next | Find similar | Unroll thread


Thread

how to add listener to li "Ray Ma" <ray.ma@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000

csiph-web