-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCenterSnap.java
More file actions
41 lines (36 loc) · 1.08 KB
/
Copy pathCenterSnap.java
File metadata and controls
41 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
/**
* The blue snap
*
* @author Derek Schafer
*/
public class CenterSnap extends Snap implements MouseMotionListener
{
private Polygon shape;
/**
* Constructor for objects of class CenterSnap
*/
public CenterSnap(int x, int y, Polygon p)
{
super(x,y,p);
shape = p;
setColor(Color.BLUE);
}
@Override
public void mouseDragged(MouseEvent e)
{
if(color.equals(Color.BLUE) && MouseInfo.getPointerInfo().getLocation().x < (Container.width*7)/8 - shape.getWidth() && MouseInfo.getPointerInfo().getLocation().y > Container.height/8 + shape.getWidth())
{
for(Snap s: shape.getSnaps())
{
s.setVisible(false);
setX(MouseInfo.getPointerInfo().getLocation().x);
setY(MouseInfo.getPointerInfo().getLocation().y-Container.height/8);
//s.repaint(); I don't think this is necessary?
}
}
}
}