I am trying to implement a mouse click event for an image (mainly a tile on a map) on a JPanel. I just can't figure out how to do this. I have a Main class that extends JPanel. I retrieve the tiles from the tile server and display them in the paintComponent () method of the Main class based on a specific zoom level. I use tiny locator images to represent a specific monument or building in a city in the same paintComponent () method. They are placed on top of these tiles based on the appropriate latitude and longitude.
When I click on these locator images, I should be able to add the MouseClick () event to the locator image. Now that I have read so far, we cannot add an event handler to the images. It can only be added to your own swing components. How do I add events to tiny locator images when I did not represent it using JLabel or even around an image with a rectangle?
java swing paintcomponent mouseevent
suhas bhairav
source share