public class ReflectiveXAction extends AbstractXAction
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 firing 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). Now 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!
changeSupport, enabled
LARGE_DISABLED_ICON, LARGE_DISABLED_SELECTED_ICON, LARGE_ICON, LARGE_PRESSED_ICON, LARGE_ROLLOVER_ICON, LARGE_ROLLOVER_SELECTED_ICON, LARGE_SELECTED_ICON, SMALL_DISABLED_ICON, SMALL_DISABLED_SELECTED_ICON, SMALL_PRESSED_ICON, SMALL_ROLLOVER_ICON, SMALL_ROLLOVER_SELECTED_ICON, SMALL_SELECTED_ICON
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
Constructor and Description |
---|
ReflectiveXAction(Object target,
String methodName)
Creates a new ReflectiveAction
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Invoked when an action occurs.
|
getAccelerator, getActionCommand, getLargeDisabledIcon, getLargeDisabledSelectedIcon, getLargeIcon, getLargePressedIcon, getLargeRolloverIcon, getLargeRolloverSelectedIcon, getLargeSelectedIcon, getLongDescription, getMnemonicKey, getName, getShortDescription, getSmallDisabledIcon, getSmallDisabledSelectedIcon, getSmallIcon, getSmallPressedIcon, getSmallRolloverIcon, getSmallRolloverSelectedIcon, getSmallSelectedIcon, setAccelerator, setActionCommand, setLargeDisabledIcon, setLargeDisabledSelectedIcon, setLargeIcon, setLargePressedIcon, setLargeRolloverIcon, setLargeRolloverSelectedIcon, setLargeSelectedIcon, setLongDescription, setMnemonicKey, setName, setShortDescription, setSmallDisabledIcon, setSmallDisabledSelectedIcon, setSmallIcon, setSmallPressedIcon, setSmallRolloverIcon, setSmallRolloverSelectedIcon, setSmallSelectedIcon
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
public ReflectiveXAction(Object target, String methodName) throws NoSuchMethodException
target
- the object with the specified methodmethodName
- the method name (must be public and take an ActionEvent
obect as its single parameter)NoSuchMethodException
- if no such method foundpublic void actionPerformed(ActionEvent e)
e
- an ActionEvent objectCopyright © 2002–2016 SoftSmithy. All rights reserved.