Catch mouse events on a drawn object (say a Polygon)
Posted on 2004-11-03
I have drawn 4 polygons on a JPanel. I wish to capture mouse events so as to say which polygon has been clicked. I can see three possible solutions, could you please tell me which are feasable and which solution you consider best ?
Solution 1 : very conveniently, Java has enabled listeners of some sort for 2D Graphic objects ... how do I catch them ?
Solution 2 : ok, Solution 1 doesn't exist : I have to extend a Swing clickable object (such as a JButton for example) and make it look like my polygon ... how do I go about this ?
Solution 3 : none of the above are possible, I therefore have to check the coordinates of the mouse click and see if it belongs to any of my polygons. I'm kind of hoping this isn't the only solution ;-)