This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How a event in a object can trigger an action in another object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How a event in a object can trigger an action in another object?" Watch "How a event in a object can trigger an action in another object?" New topic
Author

How a event in a object can trigger an action in another object?

Daniel Rodrigues
Greenhorn

Joined: Sep 03, 2003
Posts: 8
How a event in a object can trigger an action in another object?

I created a GUI which has a Jtree inside and every time that one node in the tree is selected and right clicked a popup menu with 2 menuItems shows up.
I created the popup menu as a separate class and added an ActionListener to each menuItem. Later this popup menu was added to my Jtree. (don't know if this is a reasonable approach)
Putting some println I can see the events happening as expected but I could not figure out yet how an event inside the popup menu can initiate an action in my Jtree...like create a new node for instance.

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18708
    
    8

"Dan Jmr", please check your private messages regarding an important administrative matter.

Thank you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Probably better discussed in the Swing forum.

Whenever anything happens, eg window resized, window obscured, mouse click, etc etc, that component sends an Event object. It seems to start with the inside components (eg a Button) and passes to that component. If there is a Listener listening for that sort of event. that Listener "catches" the event and does whatever is supposed to happen. If there isn't a Listener, the event passes on to the outside component, where it might be caught is there is another Listener. If it reaches the outermost component without being "listened for" the Event vanishes into a sort of cyber-limbo, never to be seen again.

That is a very informal and rough-and-ready hint about how Events are handled.
 
jQuery in Action, 2nd edition
 
subject: How a event in a object can trigger an action in another object?