?? nativemidlet.java
字號:
package com.j2medev.chapter3;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class NativeMIDlet extends MIDlet implements CommandListener {
private Display display = null;
private List main = new List("menu",List.IMPLICIT);
private Command exitCommand = new Command("Exit",Command.EXIT,1);
public static final String WAP_BROWSER = "wap browser";
public static final String TELEPHONE = "call telephone";
public void startApp() {
//初始化main菜單
if(display == null){
display = Display.getDisplay(this);
main.append(WAP_BROWSER,null);
main.append(TELEPHONE,null);
main.addCommand(exitCommand);
main.setCommandListener(this);
}
display.setCurrent(main);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == List.SELECT_COMMAND){
String label = main.getString(main.getSelectedIndex());
String URL = "";
if(label.equals(WAP_BROWSER)){
URL = "http://www.j2medev.com";
}else if(label.equals(TELEPHONE)){
URL = "tel:13810018823";
}
try{
//如果請求必須在MIDlet退出后才能響應,則退出
boolean flag = platformRequest(URL);
if(flag){
exit();
}
}catch(ConnectionNotFoundException ex){
ex.printStackTrace();
//將錯誤信息顯示到手機屏幕對調試很有幫助
Alert a = new Alert("error",ex.getMessage(),null,AlertType.ERROR);
a.setTimeout(2000);
showAlert(a);
}
}else if(cmd == exitCommand){
exit();
}
}
//顯示錯誤,警告等提示信息
private void showAlert(Alert alert){
display.setCurrent(alert,main);
}
private void exit(){
destroyApp(true);
notifyDestroyed();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -