Re: AbstractAction



Thanks for the answer.
For programatically performing action, I used the command pattern
(design patterns by GoF) which extends AbstractAction & has an execute
method. A convinent way.
For the first question i am still unclear that how an action will know
the component's selected state & take decision as SELECTED_KEY is
missing. In that case I have to pass the actual component in the
action? (Then for the components constructor wont work, neew to use
setAction instead, also the very basic idea of using one action for
multiple component will be violeted, as two action is needed for those
two components).
Or I need to pass the selected state to action additionally.


abir
Thomas Fritsch wrote:
toton wrote:
From Java 1.5 or lower version, can an Action be used for JCheckBox &
JCheckBoxMenuItem pair or JToggleButton & JCheckBoxMenuItem pair?
JCheckBox, JCheckBoxMenuItem, JToggleButton and JCheckBoxMenuItem all
have a constructor taking an Action. They also have a setAction(Action)
method inherited from AbstractButton.

Java 1.6 has Action.SELECTED_KEY but 1.5 doesnt have.
So what?

Also how to execute an Action from program? like JButton has a
doClick method. I want to execute an action from program even when the
actual button or menuitem is removed from gui, thus i dont have an
reference for the actual gui component.
You can do
Action a = ...;
ActionEvent e =
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "bla";
a.actionPerformed(e);

--
Thomas

.


Quantcast