Java AWT MouseMotionAdapter extend

Description

Java AWT MouseMotionAdapter extend

import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

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

public class Main extends JFrame {
   JLabel l = new JLabel();

   Main() {/*from   w ww  . java 2 s.co m*/
      setSize(200, 100);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setLayout(new FlowLayout());
      add(l);
      this.addMouseMotionListener(new MouseMotionAdapter() {
         public void mouseMoved(MouseEvent e) {
            l.setText(e.getX() + ", " + e.getY());
         }
      });
      setVisible(true);
   }

   public static void main(String args[]) {
      new Main();
   }
}



PreviousNext

Related