| Author |
Getting image location
|
Sunit Naik
Greenhorn
Joined: Mar 18, 2007
Posts: 7
|
|
Hi! , 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
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
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. CR
|
 |
Sunit Naik
Greenhorn
Joined: Mar 18, 2007
Posts: 7
|
|
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 ImageIcon img = new ImageIcon ("c:\\a.jpg"); labl = new JLabel(img); newContentPane.add(labl); 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. Please help me out Thanks a lot
|
 |
 |
|
|
subject: Getting image location
|
|
|