Can Images respond to mouse events?
Created Sep 28, 2001
Scott Stanchfield
For example:
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.
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
}