/* * ListDemo.java * * Created on 13 ??????? 2546, 16:38 ?. */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple "Hello" text and an Exit command. * Refer to the startApp, pauseApp, and destroyApp * methods so see how each handles the requested transition. * * @author sup98 * @version */ public class ListDemo extends MIDlet implements CommandListener { private Command exitCommand, backCommand; private Display display; // The display for this MIDlet private List menu, l1, l2, l3; public ListDemo() { display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.EXIT, 1); backCommand = new Command("Back", Command.BACK,2); } /** * Start up the Hello MIDlet by creating the TextBox and associating * the exit command and listener. */ public void startApp() { menu = new List("List Types",Choice.IMPLICIT); menu.append("Implicit",null); menu.append("Multiple",null); menu.append("Exclusive",null); menu.addCommand(exitCommand); menu.setCommandListener(this); l1 = new List("Language",Choice.IMPLICIT); l1.append("Java",null); l1.append("VB",null); l1.append("C#",null); l1.append("C++",null); l1.addCommand(backCommand); l1.setCommandListener(this); l2 = new List("Plateform",Choice.MULTIPLE); l2.append("Linux",null); l2.append("Solaris",null); l2.append("NT",null); l2.addCommand(backCommand); l2.setCommandListener(this); l3 = new List("Country",Choice.EXCLUSIVE); l3.append("Thailand",null); l3.append("Malaysia",null); l3.append("Japan",null); l3.append("Korea",null); l3.addCommand(backCommand); l3.setCommandListener(this); display.setCurrent(menu); } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } /* * Respond to commands, including exit * On the exit command, cleanup and notify that the MIDlet has been destroyed. */ public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); }else if (c == backCommand){ display.setCurrent(menu); }else if (c == List.SELECT_COMMAND){ if(s == menu){ switch(((List) s).getSelectedIndex()){ case 0 : display.setCurrent(l1); break; case 1 : display.setCurrent(l2); break; case 2 : display.setCurrent(l3); break; } } } } }