• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphics Mouse Click and Location

 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic