This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

 
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
 
Marshal
Posts: 24933
61
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.
 
Marshal
Posts: 67357
257
  • 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.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!