aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Moving Circles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Moving Circles" Watch "Moving Circles" New topic
Author

Moving Circles

Rose Jac
Ranch Hand

Joined: May 20, 2011
Posts: 33
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!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4527
    
    5

What do you have so far?


luck, db
There are no new questions, but there may be new answers.
Rose Jac
Ranch Hand

Joined: May 20, 2011
Posts: 33
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

Joined: May 03, 2008
Posts: 4527
    
    5

Post your code, in the form of an SSCCE <--link

You might want to look into using a javax.swing.Timer <-- link
Rose Jac
Ranch Hand

Joined: May 20, 2011
Posts: 33
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?
Any concrete solution please??

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rose Jac
Ranch Hand

Joined: May 20, 2011
Posts: 33
Hi.
I am not able to do that. Can you make changes to my code?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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

Joined: May 20, 2011
Posts: 33
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.


 
wood burning stoves
 
subject: Moving Circles