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

📄 fixedrateschedulemidlet.java

📁 j2me实例代码
💻 JAVA
字号:
package timeimpl;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
public class FixedRateScheduleMIDlet extends MIDlet{
	private Timer aTimer;
	private ClockTimerTask aTimerTask;
	Displayable d;
	private Date currentTime;
	private Calendar now;
	private String nowString="";
	protected 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)+"Hours"+now.get(Calendar.MINUTE)+"Minute"+now.get(Calendar.SECOND)+"Second";
		aTimer=new Timer();
		aTimerTask=new ClockTimerTask();
		aTimer.scheduleAtFixedRate(aTimerTask,10,1000);
		Display.getDisplay(this).setCurrent(d);
	}
	protected void pauseApp() {
	}
	protected void destroyApp(boolean arg0) {
	}
	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)+"Hours"+now.get(Calendar.MINUTE)+"Minute"+now.get(Calendar.SECOND)+"Second";
			((ClockCanvas)d).repaint();
		}
	}	
}

⌨️ 快捷键说明

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