2011-12-16 52 views
2

我正在问问题和答案进行测验应用程序。 我想让时钟倒数(分钟+秒),并且显示在屏幕上。 但我不能如何做到这一点。 任何人都可以帮助我吗?黑莓手机 - 如何使时钟倒计时并在屏幕上显示

+0

嗨请给一些更多的信息,你需要什么?你想问问题和答案之间的时间? – 2011-12-16 04:29:07

+0

@HelpMeToHelp您的测验游戏有时间限制(例如2分钟)。我想创建一个时钟倒数2分钟0秒到0分钟0秒。当时间完成后,测验结束。并显示在我的测验屏幕上的时钟(示例图像http://pastormikelandry.files.wordpress.com/2010/02/countdown-clock1.jpg) – 2011-12-16 04:52:34

+0

嗨,如果你有怀疑reqarding this come come this room http://chat.stackoverflow .com/rooms/4014/knowledge-sharing-center-for-blackberry-and-java – 2011-12-16 05:04:00

回答

3

这是一个解决方案来打印时间mm:ss格式(分钟:秒)

public class StartUp extends UiApplication{ 
     public static void main(String[] args) { 
      StartUp start=new StartUp(); 
      start.enterEventDispatcher(); 
     } 
     public StartUp() { 
      pushScreen(new Timerscreen()); 
     } 
    } 

      class Timerscreen extends MainScreen 
     { 
      LabelField time; 
      long mille=0; 
      Timer timer=null;TimerTask task=null; 
      public Timerscreen() { 
       mille=1000*60*1; 
       time=new LabelField(); 
       add(time); 
       timer=new Timer(); 

       task=new TimerTask() { 

        public void run() { 
         synchronized (UiApplication.getEventLock()) { 

          if(mille!=0){ 
           SimpleDateFormat date=new SimpleDateFormat("mm:ss") ; 
           System.out.println("================="+date.formatLocal(mille)+"====================="+Thread.activeCount()); 
           time.setText(date.formatLocal(mille)); 
           mille=mille-1000; 
          }else{ 
time.setText("00:00"); 
mille=1000*60*1; 
           timer.cancel(); 
           UiApplication.getUiApplication().invokeLater(new Runnable() { 
            public void run() { 
             Dialog.inform("Time expaired"); 
            } 
           }); 

          } 
         } 
        } 
       }; 
       timer.schedule(task,0, 1000); 
      } 
     } 
0

相同像以上但一些变化:

第一组:

INT秒= 120; //你想要多少秒钟;

public void callTheTimer() 
{ 
    label=new LabelField("\t"); 
    add(label); 
    timer=new Timer(); 
    timerTask=new TimerTask() 
    { 
     public void run() 
     { 
      synchronized (UiApplication.getEventLock()) 
      { 
       if(secs!=0) 
       { 
        label.setText(""+(secs--)+" secs");     
       } 
       else 
       { 
        timer.cancel();      
        UiApplication.getUiApplication().invokeLater(new Runnable() 
        { 
         public void run() 
         { 
          label.setText(""); 
          Dialog.alert("Times Up"); 
          secs=120;        
         }   
        });      
       } 
      } 
     } 
    }; 
    timer.schedule(timerTask, 0, 1000); 
} 

这就够了;

相关问题