Can Images respond to mouse events?
Created May 7, 2012
All you need to do is add a MouseListener to the component in which you are drawing the image.
If you're drawing the image in the applet itself, just add a MouseListener to the applet. If you're using a Canvas, add a mouse listener to the canvas.
For example:
public class ImageCanvas extends Canvas
implements MouseListener {
public ImageCanvas() {
addMouseListener(this);
}
public void paint(Graphics g) {
// draw image
}
public void mousePressed(MouseEvent e) {
// handle mouse being pressed
}
public void mouseReleased(MouseEvent e) {
// handle mouse being released
}
// other methods in MouseListener
}