03-04-2010 12:37 PM
If I have a button and have written some code for it's invokeAction method, is it possible to call that button's invokeAction method from a menu item?
I suppose I could just copy the code for this button and add it to the menu; I'm really just wondering if there's an easier way.
(Sorry if this has already been covered in this forum, I'm not quite sure of the kinds of search terms I would use to find a solution to my question.)
Solved! Go to Solution.
03-04-2010 02:08 PM
invokeAction is protected, so you can't call it directly. You can play games like deriving a subclass with invokeAction made public. But it's usually simpler to just have the button's listener and the menu item's listener invoke a common method. That's easy and obvious if the listeners are in the same code module and a little more complicated if they're not, of course. But, in general duplicate code is a Bad Idea, and it's even worse if the duplicates are in different modules.