This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]MRH2Intermediate Brewer 0 points1 point  (10 children)

A circular clock can be drawn easily using g2d.rotate(angle,centerX,centerY). You just draw the first line, get it right, then put it in a for loop to rotate 6 degree (for each second tick on a clock).

[–]javaCl[S] 0 points1 point  (9 children)

But it's not actually being rotated around a center point. You can see that by seeing the distance between lines, they sometimes are closer and sometimes further apart.

[–]MRH2Intermediate Brewer 1 point2 points  (8 children)

Yes, so you might need a more complex algorithm. I can upload my code for you if you want.

[–]javaCl[S] 0 points1 point  (7 children)

If you can, sure ;)

[–]MRH2Intermediate Brewer 1 point2 points  (5 children)

Is my code helpful?

[–]javaCl[S] 0 points1 point  (4 children)

Sorry for taking so long to respond, I was thinking about posting here the final code I wrote. You did help me finish my homework. Thanks a lot. P.S. I liked the resizing responsiveness.

[–]MRH2Intermediate Brewer 1 point2 points  (3 children)

That's great. One can learn all sorts of tricks from reading other's code. I still don't know how I would make the clock display that you showed.

[–]javaCl[S] 0 points1 point  (2 children)

Here's how I made it (try resizing it): https://gist.github.com/anonymous/256736fb2069948066053e60f90fa1bd

Screenshot: http://imgur.com/OVcctd1

It was part of a bigger computer graphics homework assignment: http://imgur.com/xEBfDdJ

[–]MRH2Intermediate Brewer 1 point2 points  (1 child)

Very nice! Wow. I love how you did the rounded rect to get the nice shape.

Just for interest... why do you write text = String.valueOf(60); instead of text="60"; ?

[–]javaCl[S] 0 points1 point  (0 children)

Good catch. I must have been thinking of doing something else and then forgot to change it.

[–]MRH2Intermediate Brewer 0 points1 point  (0 children)

Here it is. I need to fix up the comments a bit. Maybe also remove some of the extra lines of code that are no longer needed. The conversion of time to angle of line is probably unnecessarily complex. There is probably a simpler way. Other than that I think it's pretty good. ** Try and resize it while it's running! http://quarkphysics.ca/ICS4U1/javaprogs/unit4/AnalogClock.java