📄 listdemo.java
字号:
package ch09.section01;
import javax.microedition.lcdui.*;
//列表实例类
public class ListDemo
extends BaseListDemo {
//列表类型
private static final String[] listTypes = {
"Exclusive", "Implicit", "Multiple"};
//创建一个列表实例
public ListDemo() {
super("请选择列表类型", listTypes);
}
protected Runnable[] getListCallbacks() {
//该类用于显示列表
class DisplayList
extends List
implements Runnable, CommandListener {
//点击返回的上一层父类
private Displayable parent;
public DisplayList(String listLabel,
int listType,
String[] data,
Image[] images,
Displayable parent) {
super(listLabel, listType, data, images);
addCommand(new Command("返回", Command.BACK, 1));
setCommandListener(this);
this.parent = parent;
}
public void run() {
Display.getDisplay(UIDemo.getInstance()).setCurrent(this);
}
//响应按钮事件
public void commandAction(Command c, Displayable d) {
if (c.getCommandType() == Command.BACK) {
Display disp = Display.getDisplay(UIDemo.getInstance());
disp.setCurrent(parent);
}
}
}
String[] stringArray = {
"Option A", "Option B", "Option C"};
//创建列表形式的选择组
Runnable[] lists = {
new DisplayList("Exclusive", ChoiceGroup.EXCLUSIVE, stringArray, null, this),
new DisplayList("Implicit", ChoiceGroup.IMPLICIT, stringArray, null, this),
new DisplayList("Multiple", ChoiceGroup.MULTIPLE, stringArray, null, this)
};
return (lists);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -