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 / General / May 2007

Tip: Looking for answers? Try searching our database.

Menus

Thread view: 
Francois Lionet - 01 May 2007 18:26 GMT
Hi all,

Me again. I am working on menus right  now. Menus in Java seems rather nice
and simple, but there is one thing I do not figure out : in my action
listener, how can I detect which menu option has been chosen? Under Windows,
it is simple as you have a menu identifier and you can check it. But I see
no such thing under Java and Swing. Should I keep a pointer to every
menuitem I have created and compare it to the object returned by getSource
in the action listener? Should I derive the JMenuItem class and add a menu
identifier of my own to manage this? Or is it a simpler way of proceeding?
How do you do this in your programs?

Thanks, Francois
visionset - 01 May 2007 19:33 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
> add a menu identifier of my own to manage this? Or is it a simpler way of
> proceeding? How do you do this in your programs?

Generally speaking, either add a separate action listener to each item or
use the ActionEvent.getActionCommand() method to identify.
Usually you can use both with the latter for closely related actions.

Also, consider using the Command pattern implemented by the Action class.

Signature

Mike W



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



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