simpletimermidlet.java

来自「j2me的程序」· Java 代码 · 共 45 行

JAVA
45
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class SimpleTimerMIDlet extends MIDlet implements CommandListener {
    private Command exitCommand;
    private Command scheduleCommand;
    private TextBox aTextBox;
    public static String aMessage="";
    Display display;

    private Timer aTimer;
    private SimpleTimerTask aTimerTask;

    public SimpleTimerMIDlet() {
		Display display = Display.getDisplay(this);
        exitCommand = new Command("离开", Command.EXIT, 1);
        scheduleCommand = new Command("调度",Command.SCREEN,1);
    }

    public void startApp(){
	    aTextBox = new TextBox("定时", "调度内容", 20, 0);
        aTextBox.addCommand(exitCommand);
        aTextBox.addCommand(scheduleCommand);
        aTextBox.setCommandListener(this);
        display.setCurrent(aTextBox);
    }

  public void pauseApp() {}
  public void destroyApp(boolean unconditional) {}
  public void commandAction(Command c, Displayable s) {
	  if(c == scheduleCommand){
          aTimer = new Timer();
          aTimerTask = new SimpleTimerTask();
          aTimer.schedule(aTimerTask,500);
          aTextBox.setString(aMessage);
	  }
      else if (c == exitCommand){
         destroyApp(false);
         notifyDestroyed();
	 }

  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?