MouseMotionListener Example Applet

MouseMotionListener Example Applet

Note: Before going into this tutorial, it is advised to have better knowledge of Applet.

Applets are also capable to raise mouse and key events like with frame. Following program illustrates how to use MouseMotionListener with applet.

MouseMotionListener Example as Applet

HTML file to run the applet

Java applet File Name:

No main() method and no constructor, it is being an applet.

public class AppletMouseMotionListener extends Applet implements MouseMotionListener

Observe, the applet implements MouseMotionListener.


Applet window is added with MouseMotionListener in init() method.

The paint() method should be called with repaint() only. Calling paint() directly raises compilation error. Why?

showStatus("Mouse is moving");

showStatus(String) defined in Applet class displays in the status bar of applet window. See the output screen.

MouseMotionListener Example
Output screen of mouse events of MouseMotionListener Example

Leave a Reply

Your email address will not be published. Required fields are marked *