/Users/lyon/j4p/src/ip/graphics/MouseMovementHandler.java

1    package ip.graphics; 
2     
3    import java.awt.*; 
4    import java.awt.event.MouseEvent; 
5    import java.awt.event.MouseListener; 
6    import java.awt.event.MouseMotionListener; 
7     
8    public class MouseMovementHandler 
9            implements MouseMotionListener, 
10           MouseListener { 
11       private int w = 10; 
12       private int h = 5; 
13       private int x1,y1,x2,y2; 
14    
15       public void mouseReleased(MouseEvent e) { 
16       } 
17    
18       public void mouseEntered(MouseEvent e) { 
19       } 
20    
21       public void mouseExited(MouseEvent e) { 
22       } 
23    
24       public void mouseClicked(MouseEvent e) { 
25       } 
26    
27       public void mouseDragged(MouseEvent e) { 
28           Object o = e.getSource(); 
29           if (!(o instanceof Component)) return; 
30           Component c = (Component) o; 
31           x1 = x2; 
32           y1 = y2; 
33           x2 = e.getX(); 
34           y2 = e.getY(); 
35           c.setLocation(x2, y2); 
36           c.repaint(); 
37       } 
38    
39       public void addComponent(Component c) { 
40           c.addMouseMotionListener(this); 
41           c.addMouseListener(this); 
42       } 
43    
44       public void mouseMoved(MouseEvent e) { 
45       } 
46    
47       public void mousePressed(MouseEvent e) { 
48           x1 = e.getX(); 
49           y1 = e.getY(); 
50           x2 = -1; 
51       } 
52   } 
53