• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pros/Cons with using setActionCommand("OK") for the ActionListener  RSS feed

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any pros/cons/advantages between these two implementations?

Or is it simply preference?





 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would prefer the second, since there is no need to keep an instance variable to reference the button.

Another solution is to use a separate ActionListener (or Action), then there is no need for an if/else test.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer separating the action listener or action. This way these classes can be reused if needed.
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actions are rarely limited to just one button. Imagine you have a save action, you could call it from a toolbar and from a menu item as well. This way, you can also disable an action, and it will disable all the buttons that are using that action.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!