package src;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class TimerTest extends MIDlet
{
private Form form;
private Timer timer;
private PrintTask task;
public TimerTest()
{
form = new Form("Timer Test");
//Setup the timer and the print timertask
timer = new Timer();
task = new PrintTask();
}
protected void destroyApp(boolean b) throws MIDletStateChangeException
{
// 销毁程序
timer.cancel();
}
protected void pauseApp()
{
// 程序暂停
task.cancel();
}
protected void startApp() throws MIDletStateChangeException
{
// 程序开始入口
//display the UI
Display.getDisplay(this).setCurrent(form);
//在每一千毫秒中进行重新刷新
timer.schedule(task, 1000, 1000);
}
protected class PrintTask extends TimerTask
{
public void run()
{
//Returns the scheduled execution time of the
//most recent actual execution of this task.
form.append(""+ this.scheduledExecutionTime());
}
}
}