Hello guys,

I've been surfing the web for hours and trying different published codes to make a stopwatch work but had no luck so far so I had to come here hoping someone can guide me or refer me to a tutorial on how to make one.

The stopwatch is simply a timer the starts once the user clicks the "Start" button.

If you can guide, please do as I really need to have one.

Looking forward to your reply

thanks in advance.

1. Make a timer with a delay of 1

Timer timer = new Timer (1,this);

(make sure to implement ActionPerformed).
2. Make a start and Stop JButton and a JLabel.
3. add actionlisteners to the buttons

startButtonName.addActionListener (this);

and program them to start and stop the timer.
4. make a double called time (or whatever).
5. make it so whenever the timer goes to the actionPerformed it add one to the time (double you created in the previous step)
6. divide the double by 1000 and set it into the JLabel


That should work. Hope I helped.