aspose file tools
The moose likes Applets and the fly likes Graphics Mouse Click and Location Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "Graphics Mouse Click and Location" Watch "Graphics Mouse Click and Location" New topic
Author

Graphics Mouse Click and Location

Lou Pellegrini
Ranch Hand

Joined: Nov 11, 2003
Posts: 105
Hi,
I need to detect a mouse click and location on a item I've drawn with the Graphics class.
For example, I first draw a small rectangle like fillRect(50, 50, 50, 50); Then I do some more drawing inside the rectangle.
I will have several rectangles on the screen.
Later the mouse is clicked somewhere on a rectangle.
How can I detect that the mouse was clicked and clicked on the rectangle? How can I determine which rectangle was clicked?
Thank You in Advance for Your Help,
Lou
[ May 04, 2004: Message edited by: Lou Pe ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8263

You can either keep a list of all your "clickable areas" coordinates and, given some mouse click coordinate, do some math on each of them to see if they were clicked in, or you could make your rectangles "custom components" and add mouse listeners to each of them. Take a look at the Custom Component trail in the Java Tutorial for more on the latter option.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphics Mouse Click and Location
 
Similar Threads
dnd
MouseDragg
Detecting double clicks in a JTable
HTML Division
Opening window by clicking Paint Area !