Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Registering MouseEvents at a Graphic

 
Steven Joost
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I want to register a Mouse click at a moving square. Unfortunaly this doesn't work =(

Have you guys a clue to solve?

Post Scriptum: Can I have a Cheeseburger?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it's a square, it has bounds.
add the mouselistener to graphics panel.
check if the (current) bounds contain the
point of the mouse click.
 
Steven Joost
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
didnt check what you meant, can you give a code example?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the bounds of the square is a rectangle.
the rectangle class has a method contains(Point).
from mousePressed() you can get the point clicked.
if the rectangle contains the point clicked, the square
has been 'clicked'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic