【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了: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)
{
}
}
}
}