// ITU F2005 JMA - Homework week 02 // Exercise3.java // 2005-02-15 Kenn A. Thisted /* * Make a menu for a simple game with the following entries: * start, high-score, save, and restore. */ import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; public class Exercise3 extends MIDlet implements CommandListener { Display display = null; List menu = null; static final Command choiseCommand = new Command ("Choose", Command.ITEM, 1); static final Command exitCommand = new Command ("Exit", Command.STOP, 2); // empty constructor public Exercise3() { } public void startApp() { display = Display.getDisplay(this); menu = new List("Game Menu", Choice.IMPLICIT); menu.append("start", null); menu.append("high-score", null); menu.append("save", null); menu.append("restore", null); menu.addCommand(choiseCommand); menu.addCommand(exitCommand); menu.setCommandListener(this); display.setCurrent(menu); } public void pauseApp() { // make eligable for garbage collection display = null; menu = null; } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { String label = c.getLabel(); // can be omitted if (c == exitCommand) { destroyApp(true); } else if (c == choiseCommand) { List down = (List)display.getCurrent(); int choise = down.getSelectedIndex(); System.out.print("Choice (" + choise + "): "); switch(choise) { case 0: System.out.println(menu.getString(choise)); break; case 1: System.out.println(menu.getString(choise)); break; case 2: System.out.println(menu.getString(choise)); break; case 3: System.out.println(menu.getString(choise)); break; } choise = -1; down = null; } // if label = null; } // commandAction() }