?? highlevelevent.java
字號:
package com.j2medev.chapter3;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HighlevelEvent extends MIDlet implements CommandListener,ItemStateListener,ItemCommandListener {
private Display display = null;
private Form form = null;
private TextField input = new TextField("input something:","",25,TextField.ANY);
private StringItem button = new StringItem("","press me",StringItem.BUTTON);
private Command exit = new Command("Exit",Command.EXIT,1);
private Command ok = new Command("Ok",Command.OK,2);
public void startApp() {
if(display == null){
display = Display.getDisplay(this);
form = new Form("high level event");
form.append(input);
form.append(button);
form.addCommand(exit);
button.addCommand(ok);
//為StringItem注冊ItemCommandListener
button.setItemCommandListener(this);
//為Form注冊ItemStateListener和CommandListener
form.setItemStateListener(this);
form.setCommandListener(this);
}
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
//當exit被按下的時候,commandAction()方法被觸發
public void commandAction(Command cmd,Displayable displayable){
if(cmd == exit){
destroyApp(false);
notifyDestroyed();
}
}
//button上的Command被觸發后 commandAction()方法被觸發
public void commandAction(Command cmd,Item item){
if(item == button){
if(cmd == ok){
System.out.println("Button is pressed");
display.vibrate(2000);
}
}
}
//input狀態改變的時候,itemStateChanged方法被觸發
public void itemStateChanged(Item item){
if(item == input){
System.out.println("the input's state is changed");
display.flashBacklight(2000);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -