There are a few ways you can handle this:
Create a class of your own and extends it to JComponent
class ClickableImage extends JComponent implements MouseListener
{
private BufferedImage img;
//Include all the overridden methods for MouseListener
@Override public void mouseClicked(MouseEvent e){
//To do upon clicking on image;
}
}
You can set the image on a JButton. Add an ActionListener for those JButton(s).
Use a BufferedImage for your image, detect clicking on that image by mouse cursor position.
class ClikableImage extends Rectangle{
private BufferedImage img;
//You can include any other class members you need.
public MyClickableImage(int x, int y, int width, int height){
setBounds(x, y, width, height);
}
}
To detect click on particular image, iterate through the list of ClickableImage and check whether that ClickableImage contains the mouse cursor coordinates.
//Within a MouseListener
for(ClickableImage ci : list)
if(ci.contains(e.getX(), e.getY()))
clickedImage = ci;