我試圖在java中製作一個秒錶,看起來像00:00:00,一旦按下按鈕,它就開始計數。由於某種原因,它不會工作,但我相信有一些我失蹤了。java中的秒錶
for (;;)
{
if (pause == false)
{
sec++;
if (sec == 60)
{
sec = 0;
mins++;
}
if (mins == 60)
{
mins = 0;
hrs++;
}
String seconds = Integer.toString(sec);
String minutes = Integer.toString(mins);
String hours = Integer.toString(hrs);
if (sec <= 9)
{
seconds = "0" + Integer.toString(sec);
}
if (mins <= 9)
{
minutes = "0" + Integer.toString(mins);
}
if (hrs <= 9)
{
hours = "0" + Integer.toString(hrs);
}
jLabel3.setText(hours + ":" + minutes + ":" + seconds);
}
什麼不行? – 2012-07-19 19:05:01
或者更重要的是,這是什麼? – gobernador 2012-07-19 19:05:25
所以每個迭代= 1秒? – 2012-07-19 19:06:52