How to determine if component has an addNewListener method
OK, the answer may have something to do with reflection, or it may be easier than that... here's the goal:
Basically I am creating a high-level method that passes in any type of JComponent. In the method all I know is that the component is a JComponent. I am doing something common on all components, no matter what they are. But beyond that I want to know if the component has an addActionListener method available on it, and if it does then I will add one. How can I determine programatically in this high-level method whether a JComponent has an addActionListener method?
For example, the component could be a textfield, a button, a textarea, etc. The first two mentioned have an addActionListener method, the last of the three does not. I'd like to avoid writing extensive "if (component instanceof JButton)..." type of branching. Hmmm...is there something all components that have an addActionListener method share which I can try to cast them to, and catch those that fail with a ClassCastException? I'm stumped.
Hope this makes sense and some smart person out there can give me a clue. Thanks!