?? mobilealbum.java
字號:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
// 手機畫冊
public class MobileAlbum extends MIDlet implements CommandListener {
// 創建退出命令和返回命令
private final static Command EXIT = new Command("退出", Command.EXIT, 1);
private final static Command BACK = new Command("返回", Command.BACK, 1);
private Display display; // 設備的顯示器
private List mainList; // 用于圖片名的主列表
private Form form; // 用于顯示圖像的表單
String[] pictureName = {
"Title",
"Girl",
"Love",
"Cow"
};
String[] fileName = {
"/title.jpg",
"/girl.jpg",
"/love.jpg",
"/cow.jpg"
};
public MobileAlbum() {
display = Display.getDisplay(this); //取得設備的顯示器
}
// 重載抽象類MIDlet的抽象方法startApp()
protected void startApp() {
int num = pictureName.length; // 圖片個數
Image[] imageArray = new Image[num]; // 列表的圖標數組
try {
Image icon = Image.createImage("/icon.png"); // 創建圖標
for(int i=0;i<num;i++) {
imageArray[i] =icon;
}
} catch (java.io.IOException err) {
}
mainList = new List("手機畫冊",Choice.IMPLICIT,pictureName,imageArray); // 實例化列表
mainList.addCommand(EXIT); // 為列表加上退出命令
mainList.setCommandListener(this); // 設置命令監聽器
display.setCurrent(mainList); // 顯示列表
}
// 重載抽象類MIDlet的抽象方法destroyApp()
protected void destroyApp(boolean unconditional) {
}
// 重載抽象類MIDlet的抽象方法pauseApp()
protected void pauseApp() {
}
// 實現接口CommandListener的方法
public void commandAction(Command c, Displayable d) {
if (d.equals(mainList)) {
if (c == List.SELECT_COMMAND) {
getImage(((List)d).getSelectedIndex()); // 取得圖片放在表單上
display.setCurrent(form); // 顯示表單
}
} else {
if (c == BACK) {
display.setCurrent(mainList); // 顯示主列表
}
}
if (c == EXIT) {
destroyApp(false); // 銷毀程序
notifyDestroyed();
}
}
// 裝載并顯示圖像
protected void getImage(int index) {
Image image =null;
try {
image = Image.createImage(fileName[index]); // 以指定文件創建一個固定圖像
} catch (java.io.IOException err) {}
ImageItem imageItem = new ImageItem(null,image,ImageItem.LAYOUT_CENTER,"img"); // 為圖像image創建一個ImageItem對象imageItem
form = new Form(pictureName[index]); // 創建顯示圖像的表單
form.append(imageItem); // 把imageItem加入表單
form.addCommand(BACK); // 為表單加上返回命令
form.addCommand(EXIT); // 為表單加上退出命令
form.setCommandListener(this); // 為表單設置命令監聽器
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -