
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.43 KB | hits: 13 | expires: Never
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TimerTemplate extends MIDlet implements CommandListener
{
private Display display;
private Form fmMain;
private Command cmExit;
private Command cmStop;
private Timer tm;
private TestTimerTask tt;
private int ss, mm = 0;
public TimerTemplate()
{
display = Display.getDisplay(this);
fmMain = new Form("Timer Test");
fmMain.append("Odtwarzanie\n");
cmExit = new Command("Exit", Command.EXIT, 1);
cmStop= new Command("Stop", Command.STOP, 2);
fmMain.addCommand(cmExit);
fmMain.addCommand(cmStop);
fmMain.setCommandListener(this);
tm = new Timer();
tt = new TestTimerTask();
tm.scheduleAtFixedRate(tt, new Date(), 1000);
}
public void startApp ()
{display.setCurrent(fmMain);}
public void destroyApp (boolean unconditional){}
public void pauseApp (){}
public void commandAction(Command c, Displayable d)
{
if (c == cmStop){
tm.cancel();
}else if (c == cmExit)
{
destroyApp(false);
notifyDestroyed();
}
}
private class TestTimerTask extends TimerTask
{
public final void run()
{
fmMain.deleteAll();
fmMain.append(""+ +mm);
fmMain.append(""+ ++ss);
if ((ss % 59)== 0){
mm++;
ss=0;
}
}
}
}