2
我正在問問題和答案進行測驗應用程序。 我想讓時鐘倒數(分鐘+秒),並且顯示在屏幕上。 但我不能如何做到這一點。 任何人都可以幫助我嗎?黑莓手機 - 如何使時鐘倒計時並在屏幕上顯示
我正在問問題和答案進行測驗應用程序。 我想讓時鐘倒數(分鐘+秒),並且顯示在屏幕上。 但我不能如何做到這一點。 任何人都可以幫助我嗎?黑莓手機 - 如何使時鐘倒計時並在屏幕上顯示
這是一個解決方案來打印時間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);
}
}
相同像以上但一些變化:
第一組:
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);
}
這就夠了;
嗨請給一些更多的信息,你需要什麼?你想問問題和答案之間的時間? – 2011-12-16 04:29:07
@HelpMeToHelp您的測驗遊戲有時間限制(例如2分鐘)。我想創建一個時鐘倒數2分鐘0秒到0分鐘0秒。當時間完成後,測驗結束。並顯示在我的測驗屏幕上的時鐘(示例圖像http://pastormikelandry.files.wordpress.com/2010/02/countdown-clock1.jpg) – 2011-12-16 04:52:34
嗨,如果你有懷疑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