【发布时间】:2014-01-13 02:30:21
【问题描述】:
我正在做一个计时器,从 90 秒一直倒计时到零,但是当我运行它时,它将运行 1 秒并终止,请帮助!指出问题所在!
package TestingFile;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class TestingATimer extends JFrame
{
private Timer timer;
public int count = 90;
public TestingATimer()
{
timer = new Timer(1000, new TimerListener());
timer.start();
}
private class TimerListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if (count != 0)
{
count--;
System.out.println(count + " seconds elapsed");
}
}
}
public static void main (String [] args)
{
new TestingATimer ();
}
}
【问题讨论】:
-
嗯。也许是因为您将其设置为 1000 毫秒?