资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
*TestListMID/* To change this template, choose Tools | Templates* and open the template in the editor.*/import javax.microedition.lcdui.Choice;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.List;import javax.microedition.midlet.*;/* author Administrator*/public class TestListMID extends MIDlet implements CommandListener /这里注意如何使用/CommandListener 这个接口private final static Command CMD_EXIT = new Command(Exit, Command.EXIT, 1);private final static Command CMD_BACK = new Command(Back, Command.BACK, 1);private Display display;private List mainList;private List exclusiveList;private List implicitList;private List multipleList;private boolean firstTime;Image imageArray= null; public TestListMID() display = Display.getDisplay(this);String stringArray = 选项 A,选项 B,选项 C,选项 D; /待传入进行初始化的 String 数组,即 Choice 选项的文字部分。/这里只是为 Image数组进行初始化。 exclusiveList = new List(Exclusive, Choice.EXCLUSIVE, stringArray,imageArray);exclusiveList.addCommand(CMD_BACK);exclusiveList.addCommand(CMD_EXIT);exclusiveList.setCommandListener(this);/ExlcusiveList 的声明implicitList = new List(Implicit, Choice.IMPLICIT, stringArray, imageArray);implicitList.addCommand(CMD_BACK);implicitList.addCommand(CMD_EXIT);implicitList.setCommandListener(this);/ImplicitList 的声明multipleList = new List(Multiple, Choice.MULTIPLE, stringArray, imageArray);multipleList.addCommand(CMD_BACK);multipleList.addCommand(CMD_EXIT);multipleList.setCommandListener(this);/MutipleList 的声明firstTime = true; protected void startApp() if(firstTime) imageArray = null;try Image icon = Image.createImage(/Icon.png);/注意!这里的路径是相对路径,请大家千万注意这里的细节问题imageArray = new Image icon,icon,icon; catch (java.io.IOException err) / ignore the image loading failure the application can recover. String stringArray = Exclusive,Implicit,Multiple; mainList = new List(Choose type, Choice.IMPLICIT, stringArray,imageArray);mainList.addCommand(CMD_EXIT);mainList.setCommandListener(this);display.setCurrent(mainList);firstTime = false; protected void pauseApp() protected void destroyApp(boolean unconditional) public void commandAction(Command c, Displayable d) /注意这里是如何实现 CommandListener 这个接口的!if (d.equals(mainList) if (c = List.SELECT_COMMAND) if (d.equals(mainList) switch (List)d).getSelectedIndex() case 0: display.setCurrent(exclusiveList);break;case 1: display.setCurrent(implicitList);break;case 2: display.setCurrent(multipleList);break; else / in one of the sub-listsif (c = CMD_BACK) display.setCurrent(mainList); if (c = CMD_EXIT) destroyApp(false);notifyDestroyed();
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号