为什么我的时钟不显示秒数在增加?
public class timeTest extends javax.swing.JFrame {
public timeTest() {
initComponents();
showTime();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new timeTest().setVisible(true);
}
});
}
private javax.swing.JLabel timeLable;
private void showTime() {
Timer timer = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Calendar time = Calendar.getInstance();
timeLable.setText(time.getTime().toString());
}
});
timer.setRepeats(false);
timer.start();
}
}
我没有写代码,它是由 IDE 生成的。
最佳答案
您的计时器不重复。
timer.setRepeats(true);
将其设置为重复。
实际上你甚至不需要这个,它默认设置为 true。
关于java - 我的时钟不显示秒增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962336/