Results 1 to 20 of 56
Thread: Clock Troubles
- 05-09-2011, 11:11 PM #1
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
Clock Troubles
I have been having troubles with this applet i have been making,
the three problems i need solving are:
1. the hands of the clock are moving to random places rather than clockwise
2. i can not figure out how to refresh the graphics, the clock will not update unless you minimize and restore it
3.this app was made from demonstrations so i have a lot of extra imports that i probable don't need, if you could tell me which i can delete that would be cool too.
sadly I am not that great at java so please be as descriptive with your answers as possible
P.S. if you have any input on how to improve the look of the clock or how to make it more efficient feel free to comment.Last edited by brycepower1; 05-10-2011 at 03:53 AM. Reason: removing code
- 05-09-2011, 11:17 PM #2
To have it update every second, you'd need a thread that does that. Also, you could probably cut down a lot of code by using for-loops when drawing the clock.
- 05-09-2011, 11:18 PM #3
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
what code would you use to update it though?
- 05-09-2011, 11:19 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,068
- Blog Entries
- 3
- Rep Power
- 15
Also, if you post code please use code tags.
[code]
YOUR CODE HERE
[/code]
- 05-09-2011, 11:20 PM #5
In order to repaint an object, you can call the repaint() method. I'll leave the rest of the coding to you; you'll likely learn a whole lot more that way.
- 05-09-2011, 11:23 PM #6
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
ha ha thanks
by the way the applet is 500 by 500 with the clock in the center hence why the hands in the drawline methods start at 250,250 anyone have any ideas why the hands aren't moving as i want them too?Last edited by brycepower1; 05-09-2011 at 11:26 PM. Reason: more info
- 05-09-2011, 11:28 PM #7
Remember that Math.sin and Math.cos takes their argument in radians, not degrees. There's a nifty method in the Math class to fix that though! You can read the cods for it at Math (Java Platform SE 6)
- 05-09-2011, 11:34 PM #8
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
are you perhaps talking about the toDegrees method?
- 05-09-2011, 11:35 PM #9
Other way around; you have degrees right now (seconds*6), you want radians.
- 05-09-2011, 11:38 PM #10
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
cool thank you, i never would have figured that out on my own (been awhile since i have taken math)
any ideas on which imports i don't need?
and what did you mean by for loops?
- 05-09-2011, 11:40 PM #11
In general, extra imports doesn't hurt (there are special cases where they do hurt though!). If you want to remove the ones you don't need, try commenting out all of them and see which classes can't be found, and add those imports back. Generally not really needed though.
- 05-09-2011, 11:45 PM #12
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
hmmm i changed the seconds hand
and now the second hand doesnt show upLast edited by brycepower1; 05-10-2011 at 03:53 AM.
- 05-09-2011, 11:47 PM #13
Here's why: Math.sin takes an angle in radian. Math.toRadians changes an angle in degrees to an angle in radians. Your angle in radians is seconds*6. Thus, you need to move the Math.toRadians inside the Math.sin and Math.cos method calls.
- 05-09-2011, 11:49 PM #14
Also, unless I'm confused (it's been years since I've dealt with angles, sin and cos) you shouldn't need to split it between four different calculations. One for X and one for Y should be enough.
- 05-09-2011, 11:56 PM #15
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
that... was a bad mistake
however it looks like the hands are moving properly now other than me needing to fix the negatives in the codes
- 05-09-2011, 11:57 PM #16
I'm guessing all the hands stuck to the top-right part of the clock? :P
EDIT: Hmm. Or bottom right perhaps? Now I got unsure.
- 05-09-2011, 11:58 PM #17
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
unless im mistaken i don't think it works past 90 degrees i could be wrong though
i'll experiment a little
- 05-09-2011, 11:59 PM #18
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
they are stuck in bottom right actually, though i haven't given it enough time for the minutes and hour hands though lol
- 05-10-2011, 12:01 AM #19
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
o lol i know why its acting up like this, the way i have it set up the angle should never exceed 90 but i didnt put a limit on it yet so it will just keep on bouncing till i do
- 05-10-2011, 12:01 AM #20
Similar Threads
-
24 hour clock to 12 hour clock project.
By bs3ac in forum New To JavaReplies: 4Last Post: 01-08-2013, 10:10 AM -
Integer troubles
By Tb0h in forum New To JavaReplies: 11Last Post: 08-13-2009, 04:56 PM -
Gif decoding/LZW troubles
By hellochar in forum Advanced JavaReplies: 2Last Post: 07-14-2009, 11:26 PM -
Image troubles
By Theodoreb in forum New To JavaReplies: 24Last Post: 07-14-2009, 12:41 AM -
subclass troubles
By xf021209 in forum New To JavaReplies: 12Last Post: 04-20-2009, 11:46 PM
Bookmarks