0

i'm using this example on leepoint.net

with this code the timer starts on real time seconds, but i was wondering how i can make it start at 1 second and then let it run up to 10 seconds and start over? 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));

                    }
    }
Opoe
  • 1,337
  • 8
  • 30
  • 56

1 Answers1

2

Try this

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);
    }
}
Bala R
  • 107,317
  • 23
  • 199
  • 210