Could anyone help me move this circle around the oval? Or could anyone tell me where i should start?
Joined: Jul 20, 2012
If anyone knows how please reply soon as this is a urgent problem (assignment) because apparently my java teacher went on leave for a few weeks now for unknown reason so we had a sub teacher which doesn't know anything about java apparently and called us to figure it out ourself.
If you want something to happen repeatedly on a schedule, like every 500 milliseconds in your example, then a Swing timer is the way to go. In fact you should be using a Swing JApplet instead of an AWT Applet in your code; AWT has been obsolete for over 10 years now.
Simply have your Swing timer object repaint the applet every 500 milliseconds, and put code into the paintComponent (not paint) method which draws a different circle each time it's run.
Sure there's a method to calculate where the circle should go.
Although having said that, you really haven't said what you mean by "move this circle around the oval". I didn't see any circle in your original post, only an oval. But assuming that you might mean that the circle should be tangent to the outside (or maybe the inside) of the oval and that it should appear to roll around while continuing to be tangent to the oval, then yes, the calculation is just a matter of geometry.
However it sounds to me like that isn't going to be a very helpful answer. But at the moment it's the best I can give, based on what you've posted so far.
Joined: Jul 20, 2012
Yes that is what i meant, is there any example codes i can see as i have no knowledge of geometry.
The exact question the assignment gave is to implement the logic using multi-threads to make the ball (g.fillOval(90,25,20,20);) roll along the oval. The speed of the movement should be reasonable for a user to observe. This must be implemented using Runnable interface and its methods built in Java.
Well, first you have to find a point on the fixed oval. (Actually you have to find a set of them which are reasonably close together, but you only work with one point at a time.) Then you have to find the line which is perpendicular to the fixed oval at that point. And finally you have to find a point which is 10 pixels along that line, moving away from the oval. That's the centre of your moving circle.
At least I think that's right. But if you don't know anything about geometry then you aren't going to be able to do those calculations.