Java Help - Making an Analogue Clock

Associate
Joined
20 Jun 2004
Posts
988
Location
Manchester
Hi,

I've got to put an 'analogue' clock into this little piece of coursework im doing (a countdown game, in java) and i was wondering if anyone actually knew how to do this? i've got to get it to countdown from 30 (like on the tv show) but i dont have any idea as to how to do it.

Any help would be appreciated
 
You might find this useful if you're using Swing...

Have you had a look at the javax.swing.Timer class? This can call an action listener at a specified interval. You could, I think, use it to fire off code to redraw your clock every second. If you're using JavaScript in a HTML page then there is also a timer function you could use.

To draw the clock you might need to look at plotting points on a panel using the equation for drawing a circle. I can't remember if there is a dedicated Swing function for drawing circles.

Plotting the hands will then involve using a bit of trigonometry etc. to work out where the end point of each line will be for a given degree around an origin.

Hope that helps a bit. Been a while since I did Swing stuff so hope that's not too far off the mark.

Jim
 
Back
Top Bottom