• Post Reply Bookmark Topic Watch Topic
  • New Topic

mouseListener for graphic objects  RSS feed

 
Andre Long
Greenhorn
Posts: 2
Firefox Browser Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone my name is Andre and I have a general question. Is it possible for a graphic object (java 2D object) to have a mouseListener event associated with it and if so could you point me to an example of such.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the way to add a MouseListener is to use the addMouseListener method of Component, I don't think you could do this unless your object extends Component.

What I would try would be to add a custom MouseAdapter to the object's container, which overrides mouseClicked to check if the co-ordinates of the click are within the 2D object's bounds. This should be quite easy if the object is a Shape, because it has a handy contains method.
 
Andre Long
Greenhorn
Posts: 2
Firefox Browser Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I will give extends component a try
the shape objects I am using are my own shapes and I did not inherit from component
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!