我试图在java中制作一个秒表,看起来像00:00:00,一旦按下按钮就会开始计数。出于某种原因,它不起作用,但我确信我缺少一些东西。
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);
}