public class ReflectivePropertyChangeListener extends Object implements PropertyChangeListener
Normally there are two standard ways to implement the ActionListener interface: The first is to let a class implement the ActionListener interface and then add an object of this class to the addActionListener methods of the components fireing ActionEvents. You then have to check the source in the actionPerformed method. You end up with a big ugly, unmaintainable and unstable if-then-else- statement. The second approach is to define a class for every such component. You end up with tons of small classes all increasing the memory footprint (typically 3K per class). This approach using reflection lets you define a method for each such component avoiding the mentioned drawbacks. The new drawbacks are however:
Note: This class might change package in a
future version!
Note: This class might throw different Exceptions in a future version!
Constructor and Description |
---|
ReflectivePropertyChangeListener(Object target,
String methodName)
Creates a new ReflectiveAction
|
Modifier and Type | Method and Description |
---|---|
void |
propertyChange(PropertyChangeEvent e)
Invoked when an item has been selected or deselected by the user.
|
public ReflectivePropertyChangeListener(Object target, String methodName) throws NoSuchMethodException
target
- the object with the specified methodmethodName
- the method name (must take an ActionEvent obect as its single parameter)NoSuchMethodException
- if no such method foundpublic void propertyChange(PropertyChangeEvent e)
propertyChange
in interface PropertyChangeListener
e
- an ActionEvent objectCopyright © 2002–2016 SoftSmithy. All rights reserved.