Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Moving Multiple Objects

 
Benjamin Jasurda
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I'm currently taking my first Java Programming class. My current project involves the creation of 9 reindeer within an applet. Those reindeer have been created. Now I need to be able to move them collectively with a mouseEvent so that they follow the mouse. I can get them to be selected simultaneouslly, but they don't keep their spacing--when I select them with a mouse click, they end up piling up on top of each other.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
Presumably you're getting some x,y coordinates from the mouse event, and drawing the reindeer at those coordinates. What you'll need to do, simply stated, is use different x,y coordinates for each reindeer. You might simply use x+0, x+5, x+10 ... for the 1st, 2nd, 3rd reindeer, or you could do something more complex in which both the x and y coordinates varied for each reindeer, perhaps not even in such a linear way. But anyway, the solution to your problem is quite simple: don't draw them all in the same place!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic