This discussion is archived
1 Reply Latest reply: Feb 7, 2012 2:40 AM by 865727 RSS

How to insert a button in a form in a j2me application ?

915775 Newbie
Currently Being Moderated
Dear Friends,
I'm new to J2ME. I want to know that how to insert a button in a J2ME form. What are the button action listener available here ? Please provide sample code.
  • 1. Re: How to insert a button in a form in a j2me application ?
    865727 Newbie
    Currently Being Moderated
    Form form = new Form("Form Title");
    StringItem button = new StringItem("", "Button text", Item.BUTTON);
    Command buttonCommand = new Command("Button command", Command.ITEM, 1);

    button.setDefaultCommand(buttonCommand);
    button.setItemCommandListener(new ItemCommandListener() {
    public void commandAction(Command c, Item item) {
    System.out.println("Button was clicked");
    }
    });
    form.append(button);

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points