This Java application demonstrates how to track mouse motion and dragging using Swing.
- Java Development Kit (JDK)
- Integrated Development Environment (IDE) like IntelliJ IDEA or Eclipse
- Ensure you have JDK installed on your system.
- Open the project in your preferred IDE.
- Run the
MouseMotionclass. - Move your mouse around the window to see the coordinates displayed.
- Drag the mouse to see the updated coordinates.
The MouseMotion class implements the MouseMotionListener interface to handle mouse motion events. It creates a simple Swing application with a JFrame and a JLabel to display mouse coordinates.
mouseMoved(MouseEvent e): Updates the label text with the current mouse coordinates when the mouse is moved.mouseDragged(MouseEvent e): Updates the label text with the current mouse coordinates when the mouse is dragged.
The main method initializes an instance of the MouseMotion class, which starts the application.
This application is for educational purposes to understand mouse motion event handling in Java Swing.