This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Moving Circles

 
Rose Jac
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have so far?
 
Rose Jac
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am not able to do that. Can you make changes to my code?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic