CSenshi

Java - MouseMoveEvent Example

Oct 31st, 2020
949
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package samples;
  2.  
  3. import java.awt.event.MouseEvent;
  4.  
  5. import acm.graphics.GRect;
  6. import acm.program.*;
  7.  
  8. public class GraphicsProgramSample extends GraphicsProgram {
  9.  
  10.     GRect rect = new GRect(200, 100);
  11.  
  12.     public void init() {
  13.         addMouseListeners();
  14.     }
  15.  
  16.     public void run() {
  17.         add(rect, 200, 200);
  18.     }
  19.  
  20.     public void mouseMoved(MouseEvent e) {
  21.         int x = e.getX();
  22.         int y = e.getY();
  23.         rect.setLocation(x, y);
  24.     }
  25. }
  26.  
RAW Paste Data