Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class MousePositionTracker extends MouseMotionAdapter {
  5.  
  6.     private Point pos;
  7.     private int x=0,y=0;
  8.  
  9.     public synchronized void mouseDragged(MouseEvent e) {
  10.         pos = e.getPoint();
  11.         x = e.getX();
  12.         y = e.getY();
  13.     }
  14.     public synchronized void mouseMoved(MouseEvent e) {
  15.         pos = e.getPoint();
  16.         x = e.getX();
  17.         y = e.getY();
  18.     }
  19.  
  20.     public synchronized Point getPosition() {
  21.         if (pos == null) return new Point(0,0);
  22.         return pos;
  23.     }
  24.  
  25.     public synchronized int getX() {
  26.         return x;
  27.     }
  28.  
  29.     public synchronized int getY() {
  30.         return y;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement