programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Rob Spoor
• Bear Bibeault
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Piet Souris
• Carey Brown
• Stephan van Hulst
Bartenders:
• Frits Walraven
• fred rosenberger
• salvin francis

# Moving Circles

Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
Hi.

I have 3 circles -A, B, and C (the radii is already known). I want them to move them in a specified direction with a specified velocity, and stop them when they reach the boundary.
At any time t, i want to know the x and y coordinates of these circles. Is that possible?
Any hint on how to do the same?
Thanks!

Bartender
Posts: 5167
11
• Number of slices to send:
Optional 'thank-you' note:
What do you have so far?

Rose Jac
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
I just have the circles so far, with the radii and current (x,y) positions.

And i forgot to mention that I want the circles to stop when they reach the upper boundary of the rectangle/ applet. And they should move in forward direction only ,i.e. theta = [0, 180] (randomly generated and known beforehand, say A moves 90degree continuosly from its previous position, B in 60 and C in 120 degrees respectively).
Each circle should move in a speed given by a ratio. say, Speed of A: B : C = 1: 2 : 3.
And i want to knwo the x,y coordinates after every period of, say 10seconds. (which i think i can get using basic trigonometry, and speed,distance,time thing. Is there any other way like a method or something ?).

Thanks.

Darryl Burke
Bartender
Posts: 5167
11
• Number of slices to send:
Optional 'thank-you' note:

You might want to look into using a javax.swing.Timer <-- link

Rose Jac
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
Ok. So, i want to know the x and y coordinate periodically.i.e when x = 5, 10, 15 seconds.
How can i do that?

Sheriff
Posts: 22266
119
• Number of slices to send:
Optional 'thank-you' note:
Use a javax.swing.Timer. This runs on the EDT so it's safe to both query and modify your GUI. Just make sure to make sure the executions don't take too long to finish or the GUI will become non-responsive.

Rose Jac
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
Hi.
I am not able to do that. Can you make changes to my code?

Rob Spoor
Sheriff
Posts: 22266
119
• Number of slices to send:
Optional 'thank-you' note:
Really. Did you click on the link created for javax.swing.Timer? Did you see on that page not one but two links, one being "How to Use Timers" and the other "Using Timers in Swing Applications"? Did you click on those and read the pages they link to?

Rose Jac
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
Can somebody check this code of mine?
I meant to draw four moving circles and somthing different came up, though the four circles can be seen.