j2me学习笔记【7】——复选框的应用

package mtk; import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.ChoiceGroup; 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.StringItem; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class CheckBoxes extends MIDlet implements CommandListener { private final static Command CMD_EXIT=new Command("退出",Command.EXIT,1); private Display display; private Command process; private ChoiceGroup movies; private int movieIndex; private Form mainForm; public CheckBoxes() { display=Display.getDisplay(this); movies=new ChoiceGroup("选择你喜欢看的电影",Choice.MULTIPLE); movies.append("让子弹飞", null); movies.append("非诚勿扰", null); movies.append("赵氏孤儿", null); movies.append("大小江湖", null); process=new Command("处理",Command.SCREEN,2); mainForm=new Form("电影"); movieIndex=mainForm.append(movies); mainForm.addCommand(CMD_EXIT); mainForm.addCommand(process); mainForm.setCommandListener(this); } protected void destroyApp(boolean arg0){ } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { display.setCurrent(mainForm); } public void commandAction(Command c, Displayable d) { if(c==process){ boolean picks[]=new boolean[movies.size()]; StringItem message[]=new StringItem[movies.size()]; movies.getSelectedFlags(picks); for(int x=0;x<picks.length;x++){ if(picks[x]){ message[x]=new StringItem("",movies.getString(x)); mainForm.append(message[x]); } } mainForm.delete(movieIndex); mainForm.removeCommand(process); }else if(c==CMD_EXIT){ destroyApp(true); notifyDestroyed(); } } }

你可能感兴趣的:(c,command,cmd,null,Class,j2me)