Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Daniel Rodrigues
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Dan Jmr", please check your private messages regarding an important administrative matter.

Thank you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic