Forums Register Login

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

+Pie Number of slices to send: Send
Are there any pros/cons/advantages between these two implementations?

Or is it simply preference?





+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I prefer separating the action listener or action. This way these classes can be reused if needed.
+Pie Number of slices to send: Send
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.
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 795 times.
Similar Threads
GUI and repaint()
What is the best way to create GUI components- in-line, methods, inner classes or separate classes
Having two problem on paint
MVC
How do you get the JButton name
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:25:21.