Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2006

Tip: Looking for answers? Try searching our database.

AbstractAction

Thread view: 
toton - 29 Jun 2006 10:48 GMT
Hi,
 From Java 1.5 or lower version, can an Action be used for JCheckBox &
JCheckBoxMenuItem pair or JToggleButton & JCheckBoxMenuItem pair?
Java 1.6 has Action.SELECTED_KEY but 1.5 doesnt have.
 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.

Thanks in advance

abir
Thomas Fritsch - 29 Jun 2006 13:05 GMT
>   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);

Signature

Thomas

toton - 30 Jun 2006 06:51 GMT
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
> >   From Java 1.5 or lower version, can an Action be used for JCheckBox &
> > JCheckBoxMenuItem pair or JToggleButton & JCheckBoxMenuItem pair?
[quoted text clipped - 14 lines]
>      new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "bla";
>    a.actionPerformed(e);
Thomas Fritsch - 30 Jun 2006 10:52 GMT
[reordered]

>>>  From Java 1.5 or lower version, can an Action be used for JCheckBox &
>>>JCheckBoxMenuItem pair or JToggleButton & JCheckBoxMenuItem pair?
[quoted text clipped - 25 lines]
> the component's selected state & take decision as SELECTED_KEY is
> missing.
ActionEvent has (inherited from Action) a getSource() method. Calling it
you usually get the component which raised the event. If the component
is a JCheckBox/JToggleButton/... you can cast it and call its
isSelected() method.

> 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.

Signature

Thomas

toton - 30 Jun 2006 11:54 GMT
Thanks. Got it. They are both from AbstractButton which has isSelected.
Thus I can cust it.
abir
> [reordered]
> >
[quoted text clipped - 38 lines]
>  > two components).
>  > Or I need to pass the selected state to action additionally.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.