📄 updatemidlet.java
字号:
/*
* UpdateMIDlet.java
*
* Created on 2006年6月9日, 下午9:54
*/
package com.j2medev.chapter3;
import java.util.Random;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author ming
* @version
*/
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();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -