Menus

Discussion in 'Java' started by Francois Lionet, May 1, 2007.

  1. 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
    Francois Lionet, May 1, 2007
    #1
    1. Advertising

  2. Francois Lionet

    visionset Guest

    "Francois Lionet" <> wrote in message
    news:46377848$0$28016$...
    > 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?
    >


    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.

    --
    Mike W
    visionset, May 1, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Webb
    Replies:
    7
    Views:
    1,321
    Jeremy Cowles
    Jul 9, 2003
  2. Ken Fine
    Replies:
    0
    Views:
    328
    Ken Fine
    Jul 19, 2003
  3. Bratislav Jevtic

    asp.net menus

    Bratislav Jevtic, Oct 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    418
    Rajesh.V
    Oct 21, 2003
  4. yma

    How to create menus?

    yma, Oct 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    329
    Alvin Bruney
    Oct 30, 2003
  5. news.west.cox.net

    Select menus above flyout menus? help?

    news.west.cox.net, Dec 8, 2004, in forum: HTML
    Replies:
    8
    Views:
    781
Loading...

Share This Page