O'Reilly logo

BlackBerry Java Application Development by Bill Foust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - adding a menu to the MainScreen

  1. Add the following code to create the menu.
    // Menu items
    MenuItem _calculateAction = new MenuItem("Calculate" , 100000, 10)
    {
    public void run()
    {
    Dialog.alert("The tip is $"+Double.toString(calculateTip()));
    }
    };
    
  2. Add the menu to the screen by adding the following code snippet to the class.
    protected void makeMenu(Menu menu, int instance)
    {
    menu.add(_calculateAction);
    super.makeMenu(menu, instance);
    }

What just happened?

The first step is the declaration for the menu itself. This style may look unusual if you aren't used to it. The style is a shorthand style of declaring the menu item and utilizes a technique called anonymous classes. This shorthand style contains the member declaration, creation, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required