aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Registering MouseEvents at a Graphic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Registering MouseEvents at a Graphic" Watch "Registering MouseEvents at a Graphic" New topic
Author

Registering MouseEvents at a Graphic

Steven Joost
Greenhorn

Joined: Sep 29, 2012
Posts: 28
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Sep 29, 2012
Posts: 28
didnt check what you meant, can you give a code example?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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'
 
Consider Paul's rocket mass heater.
 
subject: Registering MouseEvents at a Graphic