I am adding a image to a frame, and i need to capture mouseclick events on that image. What is the best way of doing this ?
What i am trying to do is somehow get the current location of the image, and then compare the mouse click coordinates to see if they lie within the image co ordinates. How can i do this ?
Thanks for your suggestions
Joined: Oct 13, 2005
I presume you are familiar with the Listeners for Mouse and Mouse Motion? You should be able to use them. You should also be able to get information from the Image about its size and position and thence work out whether the click location is within the bounds of the Image.
Joined: Mar 18, 2007
I am in a Dilemma,
as I mentioned I want to capture clicks on the image, so that I can start rotating it. Initially I implemented it like this
this way I can always call getBounds() on the JLable and get its coordinates and then compare it with those which I get with the mousePressed MouseEvent. But the problem with this implementation is that later when I want to rotate the image, the method drawImage() takes in a parameter of type image and my JLable trick fails.
graphics2d.drawImage(image, x, y, this)
If I create the image as of type Image the rotation goes well, but I can�t get the coordinates of the image (though I am able to get the height and width).
Please help me out,
1. How do I get the coordinates of an Image 2. If I use JLable and ImageIcon for storing images, how do I rotate them.