Is it possible to add a listener to an image so that it will pick up mouse clicks within the bounds of the image?
Either that, or can you overlay a 'transparent' component over an image so that it will act as a listener over that graphic?
I can't work out if this is possible, and moreso how to do it in java
You should look into loading the image as a JButton.
//where the argument for the ImageIcon constructor is just the filepath
//to the image that you want to load.
ImageIcon big_world = new ImageIcon ("usable map 5 (2).JPG");
JButton myWorldButton = new JButton (big_world);
The JButton will display the image, and you can then add a listener to the JButton.
If you've never used JButtons before, you should also look into Layout managers, otherwise they might not work how you expect them to. Good luck.
I possibly phrased that badly, I need something that will track where the mouse is clicked on an image, for arguments sake, if it was split up in four, the listener would take the mouseclick coordinates and then work out which coordinate the pointer is in
JButtons allow you to addMouseActionListener's to them. The MouseActionListener that you build must have a MouseClicked(MouseEvent e)
MouseEvent should give you the methods getX() and getY() which should give you the coordinates of the cursor when its clicked. I'm not exactly sure what you're looking to do, but you should be able to implement different behaviors based on the cursor's location when the mouse was clicked.
That's the best that I can do for you, sorry.
I'd misunderstood you.
I'll try that, it should work.
If this doesn't fit your requirements you could implement it as a simple JPanel extension
that loads and displays images using a filepath/url and supply it with a MouseListener
If its an option for you then let me know, I have the code.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center