Discussion Board

Results 1 to 5 of 5

Thread: Creating Menus

  1. #1
    Registered User davewit13's Avatar
    Join Date
    Jan 2005
    Posts
    11
    hi,

    having problems creating menus in j2me.
    Found alot of code around using MenuElements, lists and all sorts of things.

    my code for the list is roughly like this:

    {
    List menu=new List("MainMenu",List.IMPLICIT);

    int num1, num2, num3,num4,num5;
    private Command cmd = new Command("Select", Command.OK, 1);
    Displayable display1;


    public void options()
    {
    num1 = 0;
    num2 = 1;
    num3 = 2;
    num4 = 3;
    num5 = 4;

    menu.append("Start Game", null);
    menu.append("High Scores", null);
    menu.append("Instructions", null);
    menu.append("About", null);
    menu.append("Exit", null);

    menu.addCommand(cmd);
    menu.setCommandListener(this);
    display1.setCommandListener(this);
    }

    The problem now is how to i check which one is pressed?

    Or is there a better way to do this?

    Is will be quick a simple menu as you can see.

    Any advice is appreciated

  2. #2
    Nokia Developer Champion balagopalks's Avatar
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,427
    Hi...
    U dont need to add Select command on to the list it will be comming automatically....

    >>The problem now is how to i check which one is pressed?

    Try using
    getSelectedIndex()

    regards
    Gopal

  3. #3
    Registered User davewit13's Avatar
    Join Date
    Jan 2005
    Posts
    11
    From the getselectedIndex() how do i reference the specific menu option.

    How will the if statement go

    if(menu.getSelecetedIndex() == ?)
    {

    }

  4. #4
    Nokia Developer Champion balagopalks's Avatar
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,427
    Hi...


    int selectedOption = optionsMenu.getSelectedIndex();

    if(selectedOption == 0)
    {
    //code for the corresponding selection
    }

    else if(selectedOption == 1)
    {
    //code for the corresponding selection
    }

    else if(selectedOption == 2)
    {
    //code for the corresponding selection
    }

    Hope this helps...

    regards
    Gopal

  5. #5
    Registered User davewit13's Avatar
    Join Date
    Jan 2005
    Posts
    11
    Thanks alot thats perfect.

    Saved me again

    cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved