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.
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.
Is that a spider in your hair? Here, threaten it with this tiny ad: