⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listdemo.java

📁 J2ME开发实例J2ME开发实例J2ME开发实例J2ME开发实例J2ME开发实例
💻 JAVA
字号:
package trainning.list;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.*;public class ListDemo extends MIDlet implements 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;    public ListDemo() {        display = Display.getDisplay(this);        String[] stringArray = {            "Option A",            "Option B",            "Option C",            "Option D"        };        Image[] imageArray = null;                exclusiveList = new List("Exclusive", List.EXCLUSIVE, stringArray, imageArray);        exclusiveList.addCommand(CMD_BACK);        exclusiveList.addCommand(CMD_EXIT);        exclusiveList.setCommandListener(this);        implicitList = new List("Implicit", List.IMPLICIT, stringArray, imageArray);        implicitList.addCommand(CMD_BACK);        implicitList.addCommand(CMD_EXIT);        implicitList.setCommandListener(this);        multipleList = new List("Multiple", List.MULTIPLE, stringArray, imageArray);        multipleList.addCommand(CMD_BACK);        multipleList.addCommand(CMD_EXIT);        multipleList.setCommandListener(this);        firstTime = true;    }    public void startApp() {        if(firstTime) {            Image[] imageArray = null;            try {                Image icon = null;                imageArray = new Image[] {                    icon,                    icon,                    icon                };            }            catch(Exception e) {                e.printStackTrace();            }            String[] stringArray = new String[] {                "Exclusive",                "Implicit",                "Multiple"            };            mainList = new List("Choose type", Choice.IMPLICIT, stringArray, imageArray);            mainList.addCommand(CMD_EXIT);            mainList.setCommandListener(this);            display.setCurrent(mainList);            firstTime = false;        }    }    public void pauseApp() {    }    public void destroyApp(boolean unconditional) {    }    public void commandAction(Command c, Displayable d) {        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 {                if(c == CMD_BACK) {                    display.setCurrent(mainList);                }            }            if(c == CMD_EXIT) {                destroyApp(false);                notifyDestroyed();            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -