?? indexmidlet.java
字號:
package com.j2medev.chapter3;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class IndexMIDlet extends MIDlet implements CommandListener{
private Display display = null;
//初始化RecordEngine
private RecordEngine engine = new RecordEngine(true);
private List list = new List("rms",List.IMPLICIT);
private Form form = new Form("Image Index");
private Command backCommand = new Command("back",Command.BACK,1);
private Command exitCommand = new Command("Exit",Command.EXIT,1);
private Command deleteCommand = new Command("delete",Command.OK,2);
private Command addCommand = new Command("add",Command.OK,3);
public void startApp() {
if(display == null){
display = Display.getDisplay(this);
String[] names = engine.getAllPictureName();
if(names != null){
for(int i = 0;i<names.length;i++){
list.append(names[i],null);
}
}
form.addCommand(backCommand);
form.setCommandListener(this);
list.addCommand(deleteCommand);
list.addCommand(addCommand);
list.addCommand(exitCommand);
list.setCommandListener(this);
display.setCurrent(list);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == List.SELECT_COMMAND){
String name = list.getString(list.getSelectedIndex());
//讀取Picture
Picture pic = engine.getPictureByName(name);
form.deleteAll();
Image img = Image.createImage(pic.img,0,pic.img.length);
form.append(pic.name);
form.append(img);
display.setCurrent(form);
}else if(cmd == backCommand){
display.setCurrent(list);
}else if(cmd == addCommand){
//添加一個Picture
engine.writeData(1);
list.deleteAll();
String[] names = engine.getAllPictureName();
if(names != null){
for(int i = 0;i<names.length;i++){
list.append(names[i],null);
}
}
}else if(cmd == deleteCommand){
//刪除一個Picture
String name = list.getString(list.getSelectedIndex());
try{
engine.deletePicture(name);
list.delete(list.getSelectedIndex());
display.setCurrent(list);
}catch(Exception ex){
ex.printStackTrace();
}
}else if(cmd == exitCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -