Java Swing: set timer start time and encode it

I use this example on leepoint.net

with this code, the timer starts in real time, but I was wondering how can I do this, start from 1 second, and then let it start up to 10 seconds and start? So from 1 to 10 and so on.

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)); } } 
0
java set time timer swing
source share
1 answer

try it

 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); } } 
+2
source share

All Articles