This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Getting image location Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Getting image location" Watch "Getting image location" New topic
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
    
    4
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Getting image location
 
Similar Threads
Displaying image which is located on local disk but not on server
Display image using getCodeBase() method
copying image and saving it as another image in java
Create Image object
Displaying pdfs from MS SQL Server