gpt4 book ai didi

Java Swing : Set starting time on timer and loop it

转载 作者:行者123 更新时间:2023-12-02 08:20:41 25 4
gpt4 key购买 nike

我正在使用这个example on leepoint.net

使用这段代码,计时器以实时秒数启动,但我想知道如何做到这一点从 1 秒开始,然后让它运行到 10 秒并重新开始?所以从 1 到 10 等等..

class ClockListener implements ActionListener {
public void actionPerformed(ActionEvent e) {

Calendar now = Calendar.getInstance();
int s = now.get(Calendar.SECOND);
_timeField.setText(String.format("%1$tS", now));

}
}

最佳答案

试试这个

class ClockListener implements ActionListener {
int count = 0;
public void actionPerformed(ActionEvent e) {
int fakeSecond = (count++ % 10) + 1;
Calendar now = Calendar.getInstance();
int h = now.get(Calendar.HOUR_OF_DAY);
int m = now.get(Calendar.MINUTE);
int s = now.get(Calendar.SECOND);
_timeField.setText("" + h + ":" + m + ":" + fakeSecond);
}
}

关于Java Swing : Set starting time on timer and loop it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5524222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com