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

📄 fixedrateschedule.java

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

public class FixedRateSchedule  extends MIDlet {

  private Timer aTimer;
  private ClockTimerTask aTimerTask;

  Displayable d;

  private Date currentTime;
  private Calendar now;

  private String nowString="";

  public void startApp() {
    d = new ClockCanvas();

    d.addCommand(new Command("Exit", Command.EXIT, 0));
    d.setCommandListener(new CommandListener() {
      public void commandAction(Command c, Displayable s) {
        notifyDestroyed();
      }
    });

    currentTime = new Date();
    now = Calendar.getInstance();
    now.setTime(currentTime);

    nowString = now.get(Calendar.HOUR)+ "时"
			  + now.get(Calendar.MINUTE)+ "分"
		      + now.get(Calendar.SECOND) + "秒";

    aTimer = new Timer();
	aTimerTask = new ClockTimerTask();
    aTimer.scheduleAtFixedRate(aTimerTask,10,1000);

    Display.getDisplay(this).setCurrent(d);
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {}

  class ClockCanvas extends Canvas {
    public void paint(Graphics g) {
      int width = getWidth();
      int height = getHeight();

      g.setGrayScale(255);
	  g.fillRect(0,0,width-1,height-1);
	  g.setGrayScale(0);
      g.drawRect(0,0,width-1,height-1);

      g.drawString(nowString, 10, 10,Graphics.TOP | Graphics.LEFT);

    }
  }

  class ClockTimerTask extends TimerTask{
      public final void run(){
		    currentTime = new Date();
		    now = Calendar.getInstance();
            now.setTime(currentTime);

		     nowString = now.get(Calendar.HOUR)+ "时"
		               + now.get(Calendar.MINUTE)+ "分"
		               + now.get(Calendar.SECOND) + "秒";

            ((ClockCanvas)d).repaint();
      }
  }
}

⌨️ 快捷键说明

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