📄 commandlistenerdemo.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CommandListenerDemo extends MIDlet implements CommandListener
{
private Display display;
private Alert alert;
private Form form;
private Command exit;
private Command submit;
public CommandListenerDemo()
{
display = Display.getDisplay(this);
exit = new Command("退出", Command.EXIT, 1);
submit=new Command("提交", Command.SCREEN, 2);
form = new Form("CommandListener监听器");
form.addCommand(exit);
form.addCommand(submit);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
throws MIDletStateChangeException
{
if (unconditional == false)
{
throw new MIDletStateChangeException();
}
}
public void commandAction(Command command, Displayable displayable)
{
if (command == submit)
{
alert = new Alert("监听器", "响应Command触发的事件",
null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, form);
}
else if(command==exit)
{
try
{
destroyApp(false);
notifyDestroyed();
}
catch (MIDletStateChangeException exception)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -