⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixedrateschedulemidlet.java

📁 j2me的程序
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class FixedRateScheduleMIDlet extends MIDlet implements CommandListener {

  private Command exitCommand;
  private Display display;

  TextBox t;

  private Timer aTimer;
  private ClockTimerTask aTimerTask;

  private Date currentTime;
  private Calendar now;

  public FixedRateScheduleMIDlet() {
      display = Display.getDisplay(this);
      exitCommand = new Command("离开", Command.EXIT, 1);
      currentTime = new Date();
      now = Calendar.getInstance();
      now.setTime(currentTime);
      System.out.println("now : " + now);
  }

  public void startApp() {
    t = new TextBox("设置时间","", 256, 0);

    aTimer = new Timer();
	ClockTimerTask aTimerTask = new ClockTimerTask();

    aTimer.schedule(aTimerTask,1000,1000);

    t.addCommand(exitCommand);
    t.setCommandListener(this);
    display.setCurrent(t);
  }


  public void pauseApp() { }

  public void destroyApp(boolean unconditional) { }

  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    }
  }

  class ClockTimerTask extends TimerTask{
         public final void run(){
			 t.setString("" + now.get(Calendar.HOUR)+ "时"
			                + now.get(Calendar.MINUTE)+ "分"
			                + now.get(Calendar.SECOND) + "秒");
			 display.setCurrent(t);
 //    	       cancel();
         }
  }


}

⌨️ 快捷键说明

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