• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clickable area  RSS feed

 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How do I make a clickable area on a frame, so that an event listener can react when the area is clicked?
Thanks
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using AWT, extend java.awt.Component and override paint() to mark the region. If you are using Swing, extend javax.swing.JComponent and override paintComponent(). In either case, use setBounds() to set the region's position and size and add a MouseListener to receive the mouse click.
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a mouseListener to your component and check the coordinates that you want to using the MouseEvent's getX and getY methods.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!