Demonstrates mouse motion events : MouseMotionListener « Swing Event « Java Tutorial






Demonstrates mouse motion events
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;

class CustomListener implements MouseMotionListener {
  public void mouseMoved(MouseEvent me) {
    System.out.println("mouseMoved");
  }

  public void mouseDragged(MouseEvent me) {
    System.out.println("mouseDragged");
  }
}

public class MouseMotionListenerDemo {

  public static void main(String[] a) {
    JFrame frame = new JFrame("Popup JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel();

    label.addMouseMotionListener(new CustomListener() {
    });

    frame.add(label);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }

}








15.30.MouseMotionListener
15.30.1.The MouseMotionListener Interface
15.30.2.Demonstrates mouse motion eventsDemonstrates mouse motion events
15.30.3.How to Write a Mouse-Motion ListenerHow to Write a Mouse-Motion Listener
15.30.4.Handle mouse motion event