Asked by JJ
I have to create an analog clock..What methods should i use
Answers
Answered by
MathMate
It is a very interesting problem, regarding time (clock).
First, most computers use local time, which in general is related to universal time (commonly called GMT) with a number of hours of difference.
If you are contented with a clock that has the seconds hand moving every second, you may consider the "Timer" class, which allows you to start the clock and have a call to a given method regularly thereafter, a second, or a minute, etc.
If you want to completely synchronize with the computer clock, you may be better off using the Calendar class, which allows you to count the number of milliseconds since January 1st, 1970, and move the hands accordingly.
Of course, you would require to draw the clock and the hands. Depending on your ambition, you could draw the hands with a simple arrow, or with a width, etc. You can handle all these using the java.awt.graphics class.
There are plenty of examples on the net, the following is one example:
http://leepoint.net/notes-java/examples/animation/50analogclockbuf/analogclockbufexample.html
Try to dig up others and compare the methods each one uses.
First, most computers use local time, which in general is related to universal time (commonly called GMT) with a number of hours of difference.
If you are contented with a clock that has the seconds hand moving every second, you may consider the "Timer" class, which allows you to start the clock and have a call to a given method regularly thereafter, a second, or a minute, etc.
If you want to completely synchronize with the computer clock, you may be better off using the Calendar class, which allows you to count the number of milliseconds since January 1st, 1970, and move the hands accordingly.
Of course, you would require to draw the clock and the hands. Depending on your ambition, you could draw the hands with a simple arrow, or with a width, etc. You can handle all these using the java.awt.graphics class.
There are plenty of examples on the net, the following is one example:
http://leepoint.net/notes-java/examples/animation/50analogclockbuf/analogclockbufexample.html
Try to dig up others and compare the methods each one uses.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.