📄 commandactionhandle1.java
字号:
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class CommandActionHandle1 extends MIDlet implements CommandListener {
Display display;
Form frmMain = new Form("命令按钮事件处理演示");
static final String EXIT_STR = "退出";
static final String SCREEN1_STR = "SCREEN1";
static final String SCREEN2_STR = "SCREEN2";
static final String SCREEN3_STR = "SCREEN3";
public CommandActionHandle1() {
super();
// TODO Auto-generated constructor stub
}
protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
frmMain.addCommand(new Command(SCREEN3_STR, Command.SCREEN, 3));
frmMain.addCommand(new Command(SCREEN2_STR, Command.SCREEN, 2));
frmMain.addCommand(new Command(SCREEN1_STR, Command.SCREEN, 1));
frmMain.addCommand(new Command(EXIT_STR, Command.EXIT, 1));
frmMain.setCommandListener(this);
display.setCurrent(frmMain);
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0)
throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
//处理命令按钮事件
public void commandAction(Command c, Displayable d) {
//另外一种处理方式
String s = c.getLabel();
if (s.equals(EXIT_STR)) {
notifyDestroyed();
} else {
frmMain.append(s+ "按钮被按下\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -