-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
69 lines (64 loc) · 1.68 KB
/
Copy pathSquare.java
File metadata and controls
69 lines (64 loc) · 1.68 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//henry bogardus
import java.awt.Graphics2D;
import java.awt.Color;
public class Square extends Shape
{
public Square(ShapeManager shapeManager, Point mPoint1)
{
super(shapeManager, mPoint1);
}
public void drawShape(Graphics2D g2)
{
int x1 = mPoint1.getX();
int x2 = mPoint2.getX();
int y1 = mPoint1.getY();
int y2 = mPoint2.getY();
int width = Math.abs(x2-x1);
int height = Math.abs(y2-y1);
if (width < height)
height = width;
else if (height < width)
width = height;
if (x1 > x2 && y1 > y2)
{
if (x1-x2 > y1-y2)
{
x2 = x1 + y2 - y1;
}
else if (y1-y2 > x1-x2)
{
y2 = y1 + x2 - x1;
}
drawSquare(g2, x2, y2, width, height);
}
else if (x1 > x2)
{
if (x1-x2 > y1-y2)
{
x2 = x1 - width;
}
drawSquare(g2, x2, y1, width, height);
}
else if (y1 > y2)
{
if (y1-y2 > x1-x2)
{
y2 = y1 - height;
}
drawSquare(g2, x1, y2, width, height);
}
else
{
drawSquare(g2, x1, y1, width, height);
}
}
public void drawSquare(Graphics2D g2, int x, int y, int width, int height)
{
g2.setColor(mFillColor);
if (mFillColor != Color.white)
g2.fillRect(x, y, width, height);
g2.setColor(mPenColor);
g2.setStroke(mLineThickness.getStrokeInformation());
g2.drawRect(x, y, width, height);
}
}