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); }
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 inner member code for the run
method, all wrapped together in one concise fragment. This technique certainly makes the coding easier to make and read, but you should understand that this is just a shortcut and that behind the scenes, the compiler...