Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.43 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.*;
  2. import javax.microedition.midlet.*;
  3. import javax.microedition.lcdui.*;
  4.  
  5. public class TimerTemplate extends MIDlet implements CommandListener
  6. {
  7.   private Display display;    
  8.   private Form fmMain;        
  9.   private Command cmExit;    
  10.   private Command cmStop;    
  11.   private Timer tm;          
  12.   private TestTimerTask tt;    
  13.   private int ss, mm = 0;        
  14.  
  15.   public TimerTemplate()
  16.   {
  17.     display = Display.getDisplay(this);
  18.     fmMain = new Form("Timer Test");
  19.     fmMain.append("Odtwarzanie\n");
  20.     cmExit = new Command("Exit", Command.EXIT, 1);
  21.     cmStop= new Command("Stop", Command.STOP, 2);
  22.     fmMain.addCommand(cmExit);
  23.     fmMain.addCommand(cmStop);
  24.     fmMain.setCommandListener(this);
  25.     tm = new Timer();
  26.     tt = new TestTimerTask();
  27.     tm.scheduleAtFixedRate(tt, new Date(), 1000);
  28.   }
  29.         public void startApp ()
  30.         {display.setCurrent(fmMain);}
  31.  
  32.  
  33.   public void destroyApp (boolean unconditional){}
  34.  
  35.   public void pauseApp (){}
  36.  
  37.   public void commandAction(Command c, Displayable d)
  38.   {
  39.     if (c == cmStop){
  40.       tm.cancel();
  41.     }else if (c == cmExit)
  42.         {
  43.       destroyApp(false);
  44.       notifyDestroyed();
  45.     }
  46.   }
  47.  
  48.   private class TestTimerTask extends TimerTask
  49.   {
  50.     public final void run()
  51.     {
  52.       fmMain.deleteAll();      
  53.       fmMain.append(""+ +mm);
  54.       fmMain.append(""+ ++ss);
  55.         if ((ss % 59)== 0){
  56.         mm++;
  57.         ss=0;
  58.         }
  59.      }
  60.    }
  61. }