Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

event handling  RSS feed

 
Tal Tal
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
suppose i have a class A
this class creates an instance of class B
class B is a Dialog which has a JButton.
i would like to listen for events occurs on that button and to "catch" them
from class A.
how can i do that?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somehow, get a reference to the JButton object, have A implement ActionListener, then call theButton.addActionListener(theA). If you're the author of the B class, it's easy enough to add a getButton() method to provide access to the button. If not, you can use the getComponent(int) and getComponentCount() methods of Container to walk through the Dialog and its children until you find the JButton of interest.
 
Tal Tal
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am the author of the B class, and that idea should work
thanks
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!