?? baselistdemo.java
字號:
package ch09.section01;
import javax.microedition.lcdui.*;
//BaseListDemo類為所有列表類控件的容器框架類,并且提供一個統一的返回按鈕。
public abstract class BaseListDemo
extends List
implements CommandListener {
//存儲本實例中涉及到的所有按鈕
private Command[] commands = UIDemo.getDemoCommands();
//獲取與按鈕匹配的事件
private Runnable[] callbacks = UIDemo.getDemoActions();
//獲取與列表匹配的事件
private Runnable[] listCallbacks;
//構造器用于創建一個給定窗體標題的框架對象。
public BaseListDemo(String title) {
super(title, IMPLICIT);
initCommands();
}
//構造器用于創建一個給定窗體標題的框架對象。
public BaseListDemo(String title, String[] data) {
super(title, IMPLICIT, data, null);
initCommands();
}
//添加事件監聽器
private void initCommands() {
setCommandListener(this);
for (int iter = 0; iter < commands.length; iter++) {
addCommand(commands[iter]);
}
listCallbacks = getListCallbacks();
}
//用于響應按鈕事件
public void commandAction(Command c, Displayable d) {
for (int iter = 0; iter < commands.length; iter++) {
if (commands[iter] == c) {
callbacks[iter].run();
return;
}
}
//用于響應列表事件
listCallbacks[getSelectedIndex()].run();
}
protected abstract Runnable[] getListCallbacks();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -