?? updatemidlet.java
字號:
package com.j2medev.chapter3;
import java.util.Random;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class UpdateMIDlet extends MIDlet implements CommandListener {
private Display display = null;
private Form main = new Form("application");
private Command exitCommand = new Command("Exit",Command.EXIT,1);
public void startApp() {
if (display == null) {
display = Display.getDisplay(this);
main.append("when quit application,check update");
main.addCommand(exitCommand);
main.setCommandListener(this);
}
display.setCurrent(main);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
private boolean checkUpdate(){
//返回值為1需要更新,0不需要更新
int i = (new Random().nextInt()>>>1)%2;
return (i>0)?true:false;
}
public void commandAction(Command command, Displayable displayable) {
if(command == exitCommand){
//退出前檢查是否需要更新MIDlet套件
if(checkUpdate()){
try{
//從jad文件中讀取更新中心的地址并更新
String url = this.getAppProperty("update");
if(url != null)
platformRequest(url);
}catch(ConnectionNotFoundException ex){
ex.printStackTrace();
}
}
destroyApp(true);
notifyDestroyed();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -