Stopclock project (java).

Caporegime
Joined
12 Mar 2004
Posts
29,955
Location
England
I've decided to make a simple stop clock because I can't be bothered to go into town and buy one. I'm not entirely sure how to go about it though because the oracle course that I did supplied us with a crap book.

Would it be a good idea to create a thread so that I can use the sleep method to make sure the count only goes up every 1000ms?

As you can tell the course has given me no idea how to go about creating anything that could be used in the real world.:p
 
Last edited:
Using Thread.sleep is one way to do it yes. If you just want to just do timing you can don't need to use it thought.

You can just have a few methods in a stopwatch class:
Start - Initialises your startTime (System.getCurrentTimeMillis());
Stop - Initialises the time you stopped the timer (System.getCurrentTimeMillis()).
Elapse Time - Calculates the difference between the two.

There is a Timer class also build into the java api (Called Timer).

I wrote a scheduler a few years ago I can dig out the code if your interested.
 
using sleep is not always accurate though. maybe you could check for an internet connection and synchronise with an ntp server which can keep accurate time and use sleep only if the connection fails?
 
Back
Top Bottom