• Post Reply Bookmark Topic Watch Topic
  • New Topic

ActionListeners in Separate Class/File  RSS feed

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to put my actionlisteners in a separate class so I can reuse them in multiple places. However, I cannot figure out how to reference the parent to take the appropriate action. For example the simple case of a cancel button. Given this class:

Supposed this class was instantiated as another class's JButton listener. What do I use to Dispose of that Window? TIA.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would tend to put things like this in the area of the GUI it's used, but if you really want this then you can give that listener a constructor that takes a suitable parameter that you can then call dispose on.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use that action for several buttons in different classes rather then repeat it and have to make changes in several places if necessary. However, I did not think of passing the parent in a constructor and that solves the problem. Thanks.
 
Stephan van Hulst
Saloon Keeper
Posts: 7961
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Edit]

I realized my reply had little to do with your question, so I moved it to your other topic: http://www.coderanch.com/t/665986/GUI/java/Organizing-ActionListeners#3104215
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!