SWING - Event Listeners-MouseMotionListener Interface - Java Swing

What is SWING MouseMotionListener Interface?

Introduction

The interface MouseMotionListener is used for receiving mouse motion events on a component. The class that processes mouse motion events needs to implements this interface.

Class Declaration

Following is the declaration for java.awt.event.MouseMotionListener interface −

Interface Methods

Sr.No. Method & Description
1
void mouseDragged(MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged.
2
void mouseMoved(MouseEvent e)
Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.

Methods Inherited

This class inherits methods from the following interface −

java.awt.event.EventListener

MouseMotionListener Example

Create the following Java program using any editor of your choice in say D:/ > SWING > com > wisdomjobs> gui >

SwingListenerDemo.java

Compile the program using the command prompt. Go to D:/ > SWING and type the following command.

If no error occurs, it means the compilation is successful. Run the program using the following command.

Verify the following output.

swing_mousemotionlistener

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Swing Topics