This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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'
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Registering MouseEvents at a Graphic