?? commandmidlet.java
字號:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
// MIDlet類作為CommandListener的實現類
public class CommandMIDlet extends MIDlet
implements CommandListener {
private Display display;
private GCanvas canvas;//聲明GCanvas對象
Command command1 = new Command("文字1", Command.OK, 0);
Command command2 = new Command("文字2", Command.OK, 1);
Command command3 = new Command("文字3", Command.OK, 2);
//聲明并創建4個command對象
public void startApp() {
if (display==null)
display = Display.getDisplay(this);
if (canvas == null){
canvas = new GCanvas();//創建GCanvas對象
Command exitCommand =
new Command("退出", Command.EXIT, 0);//左下角菜單欄顯示退出按鈕
canvas.addCommand(exitCommand);//加入Command對象
canvas.addCommand(command1);
canvas.addCommand(command2);
canvas.addCommand(command3);
//OCanvas對象作為事件源
canvas.setCommandListener(this);
}
display.setCurrent(canvas);//顯示GCanvas對象
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
//CommandMIDlet需要實現commandAction方法
//判斷command的類型;或判斷對象是否相等
public void commandAction(Command c, Displayable d) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);//退出本MIDlet
notifyDestroyed();
return;
}
if (c==command1) {
TextBox txt1=new TextBox("實驗中1","This is my second MIDlet",256,0);
display.setCurrent(txt1);
return;//顯示一段信息之后退出
}
if (c==command2) {TextBox txt2=new TextBox("實驗中2","Do you think it is a good work?",256,0);
display.setCurrent(txt2);
return;}
if (c==command3) {display.setCurrent(new Alert("Thank you for watching"),canvas);
return;}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -