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

📄 timertasktest.java

📁 J2ME开发实例代码! 内含有可执行的代码!
💻 JAVA
字号:
//TimerTaskTest.java
import javax.microedition.midlet.*; 
import javax.microedition.lcdui.*; 
import java.util.*; 
 
public class TimerTaskTest extends MIDlet implements CommandListener  
{ 
	private Display display; 
	private Form props; 
	private StringItem item; 
	
	private Command exitCommand = new Command("Exit", Command.EXIT, 1); 
 
	public TimerTaskTest()  
	{ 
		display = Display.getDisplay(this); 
	} 
 
	public void startApp()  
	{ 
		props = new Form("TimerTask"); 
		item = new StringItem( "Now ", "" );
		props.append(item); 
		props.addCommand(exitCommand); 
		props.setCommandListener(this); 
		display.setCurrent(props); 
		Timer timer = new Timer();
		TimerTask task = new ShowTimeTask( item, display );
		timer.schedule( task, 0, 1000 ); //每秒钟执行一次
	} 
 
	public void commandAction(Command c, Displayable s)  
	{ 
		if (c == exitCommand)  
		{ 
			destroyApp(false); 
			notifyDestroyed(); 
		}		
	} 
 
	public void destroyApp(boolean unconditional)  
	{ 
	} 
 
	public void pauseApp()  
	{ 
	} 
 
} 

class ShowTimeTask extends TimerTask
{
	private StringItem item;
	private Display display;
	ShowTimeTask( StringItem item, Display display )
	{
		this.item = item;
		this.display = display;
	}
	public void run()
	{
		if( item == null || display == null ) return;
		Calendar c = Calendar.getInstance();
		int m = c.get( Calendar.MINUTE );
		int s = c.get( Calendar.SECOND );
		item.setText( m + " : " + s );
		if( s == 0 )display.flashBacklight(2000); //每分种闪烁一下
	}
}



⌨️ 快捷键说明

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