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

📄 listdemo.java

📁 javaME useful code with the J2ME helpful learning cla
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class ListDemo 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;
public ListDemo() {
display = Display.getDisplay(this);
String[] stringArray = {
"Option A",
"Option B",
"Option C",
"Option D"
};
//待传入进行初始化的String 数组,即Choice 选项的文字部分。
Image[] imageArray = null;
//我们这里只是为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) {
Image[] imageArray = null;
try
{
Image icon = Image.createImage("/midp/uidemo/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 destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
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-lists
if (c == CMD_BACK) {
display.setCurrent(mainList);
}
}
if (c == CMD_EXIT) {
destroyApp(false);
notifyDestroyed();
}
}
}

⌨️ 快捷键说明

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