import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.List; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class listTest extends MIDlet implements CommandListener{ private Display display; private Command cmd1; private Command cmd2; private List list; public listTest() { display = Display.getDisplay(this); list = new List("武器选择", List.EXCLUSIVE); list.append("usp", null); list.append("m4", null); list.append("awp", null); list.append("ak47", null); list.append("shaying", null); cmd1 = new Command("确定", Command.OK, 1); cmd2 = new Command("返回", Command.BACK, 1); list.addCommand(cmd1); list.setCommandListener(this); } protected void startApp() throws MIDletStateChangeException { display.setCurrent(list); } public void commandAction(Command arg0, Displayable arg1) { if(arg0==cmd1){ int n = list.getSelectedIndex(); String str = list.getString(n); list.isSelected(n); Form form = new Form("您选中的武器:"); form.append(str); form.addCommand(cmd2); form.setCommandListener(this); display.setCurrent(form); } if(arg0==cmd2){ display.setCurrent(list); } } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } }