This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

MouseEvent too slow or am I missing something?

 
Ivan Slavka
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi guys,

a month ago I decided to try to create a simple game. Well actually it's mostly playing with Java2D then creating a game.
Anyway here is my problem. I decided to learn how to move a shape (Sphere) based on the mouse position.
Ex. If I drag the mouse, the sphere follows the mouse, if I just press the button the sphere starts to move toward the mouse position.

My problem is I can't figure out how to stop the sphere when it's bounds contain the mouse position, basically when the sphere gets to the mouse it should stop.
Well to be more precise, I know how to do the logic to calculate if the mouse point is inside the sphere bounds, but the sphere doesn't stop. It just passes through.
And on some occasions when I start to drag the mouse very fast it stops.

At first I thought that it was concurrency problem (Main thread paints the sphere, MouseEvent thread assigns the mouse position), and I tested with locks, but the result was the same.
Is it possible that Java is just too slow for even this kind of simple animation, or am I missing something?

Here is my code:

Main class


Ball class
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please UseOneThreadPerQuestion. I'm locking this one. Continue in http://www.coderanch.com/t/566611/GUI/java/MouseEvent-too-slow-or-missing
 
    Bookmark Topic Watch Topic
  • New Topic