package org.kodejava.example.swing;
import javax.swing.*;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseEvent;
public class MouseMotionListenerDemo extends JFrame {
public MouseMotionListenerDemo() {
initComponents();
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(400, 400);
JTextArea textArea = new JTextArea("Hello World... try to move the mouse, click and drag it...");
textArea.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
System.out.println("Mouse Dragged...");
}
public void mouseMoved(MouseEvent e) {
System.out.println("Mouse Moved...");
}
});
getContentPane().add(textArea);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new MouseMotionListenerDemo().setVisible(true));
}
}
Wayan Saryada
Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup of coffee or tea. Thank you 🥳
Latest posts by Wayan Saryada (see all)
- How do I set the time of java.util.Date instance to 00:00:00? - October 24, 2019
- How to Install Consolas Font in Mac OS X? - March 29, 2019
- How do I clear the current command line in terminal? - February 14, 2019