📄 itemcommandevent_midlet.java
字号:
package ch04;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ItemCommandEvent_MIDlet
extends MIDlet
implements CommandListener,
ItemCommandListener {
//声明一个窗体对象
private Form aform;
//声明一个退出按钮
private Command exitCommand;
//声明一个响应超连模式标签按钮
private Command hllinkCommand;
//声明一个响应按钮模式标签按钮
private Command bCommand;
//声明一个Display对象
private Display aDisplay;
//声明一个超连模式标签
private StringItem hlstringItem;
//声明一个按钮模式标签
private StringItem bstringItem;
//声明一个响应超连模式标签的提示框
private Alert hlAlert;
//声明一个响应按钮模式标签的提示框
private Alert bAlert;
/*
1.构造器
*/
public ItemCommandEvent_MIDlet() {
exitCommand = new Command("退出", Command.EXIT, 1);
hllinkCommand = new Command("响应超连模式标签", Command.ITEM, 2);
bCommand = new Command("响应按钮模式标签", Command.ITEM, 2);
aform = new Form("ItemCommandListener事件监听器");
hlstringItem = new StringItem(null, "我是一个超连模式标签", Item.HYPERLINK);
hlstringItem.setItemCommandListener(this);
hlstringItem.setDefaultCommand(hllinkCommand);
bstringItem = new StringItem(null, "我是一个按钮模式标签", Item.BUTTON);
bstringItem.setItemCommandListener(this);
bstringItem.setDefaultCommand(bCommand);
hlAlert = new Alert("HYPERLINK模式StringItem", "你选择了超连模式标签!"
, null, AlertType.INFO);
bAlert = new Alert("BUTTON模式StringItem", "你选择了按钮模式标签!"
, null, AlertType.INFO);
aform.append("请选择一种标签,点击它。");
aform.append("\n");
aform.append(hlstringItem);
aform.append(bstringItem);
aform.addCommand(exitCommand);
aform.setCommandListener(this);
aDisplay = Display.getDisplay(this);
aDisplay.setCurrent(aform);
}
/*
2.响应按钮事件
*/
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
/*
3.响应条目按钮事件
*/
public void commandAction(Command c, Item i) {
if (c == hllinkCommand) {
aDisplay.setCurrent(hlAlert, aform);
}
else if (c == bCommand) {
aDisplay.setCurrent(bAlert, aform);
}
}
//启动应用程序
public void startApp() throws MIDletStateChangeException {
}
//挂起应用程序
public void pauseApp() {
}
//撤销应用程序
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -