Task: Write an applet that plays a sound and displays an image wherever you press the mouse on the applet. When the applet first starts it should display the image at (x,y) = (20,20). See Figure 8.3, “Mouse Exercise Applet” for an example of how the applet works.
You can see my solution working here -
MouseSolution.html
Hints: There are a few things that you will need to know:
The MouseEvent
object e
has a method getX()
and getY()
that you can use. Both these methods return an int
.
You may need to force the display to be refreshed. You could call the paint()
method, but it is not easy. The Applet
class has a method called repaint()
that you can call simply by entering this.repaint();
© 2006
Dr. Derek Molloy
(DCU).