ItemCommandListenerDemo.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.MIDlet;
- public class ItemCommandListenerDemo extends MIDlet
- {
- private final static Command CMD_STOP = new Command("暂停",
- Command.ITEM, 1);
- private final static Command CMD_RESTART = new Command("重新开始",
- Command.ITEM, 2);
- private final static Command CMD_EXIT = new Command("退出",
- Command.ITEM, 3);
- private Display display;
- private NonInteractiveGaugeRunnable nonInteractive;
- private Form mainForm;
- private Thread mThread;
- public ItemCommandListenerDemo() {
- display = Display.getDisplay(this);
- mainForm = new Form("Gauge演示");
- nonInteractive = new NonInteractiveGaugeRunnable(
- "非交互模式", 10, 0);
- mThread = new Thread(nonInteractive);
- mThread.start();
- mainForm.append(nonInteractive);
- nonInteractive.addCommand(CMD_STOP);
- nonInteractive.addCommand(CMD_RESTART);
- nonInteractive.addCommand(CMD_EXIT);
- ItemCommandListener listener = new ItemCommandListener(){
- public void commandAction(Command command, Item item) {
- if(item == nonInteractive){
- if(command == CMD_STOP)nonInteractive.stop();
- if(command == CMD_RESTART)nonInteractive.reStart();
- if(command == CMD_EXIT){
- destroyApp(false);
- notifyDestroyed();
- }
- }
- }
- };
- nonInteractive.setItemCommandListener(listener);
- }
- /**
- * Signals the MIDlet to start and enter the Active state.
- */
- protected void startApp() {
- display.setCurrent(mainForm);
- }
- /**
- * Signals the MIDlet to terminate and enter the Destroyed state.
- */
- protected void destroyApp(boolean unconditional) {
- nonInteractive.setDone();
- }
- /**
- * Signals the MIDlet to stop and enter the Paused state.
- */
- protected void pauseApp() {
- }
- }