• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Moving Circles

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you have so far?
 
Rose Jac
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I am not able to do that. Can you make changes to my code?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic