-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiamondClass.java
77 lines (64 loc) · 1.52 KB
/
DiamondClass.java
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
70
71
72
73
74
75
76
77
// The DiamondClass Class
// Second in a series of demonstration programs for introducing Java
import hsa.Console;
import java.awt.*;
class DiamondClass extends SuitClass
{
DiamondClass ()
{
}
DiamondClass (int h)
{
setHeight (h);
}
public void draw (Console c)
{
// declare two arrays for X & Y coordinates of Diamond
int iPointsX[] = new int [4];
int iPointsY[] = new int [4];
// calculate points on diamond & store in the arrays
iPointsX [0] = cx - width / 2;
iPointsY [0] = cy;
iPointsX [1] = cx;
iPointsY [1] = cy - height / 2;
iPointsX [2] = cx + width / 2;
iPointsY [2] = cy;
iPointsX [3] = cx;
iPointsY [3] = cy + height / 2;
// draw the diamond using methods available from the Console object (c)
c.setColor (iColor);
if (isFilled)
{
c.fillPolygon (iPointsX, iPointsY, 4);
}
else
{
c.drawPolygon (iPointsX, iPointsY, 4);
}
}
public void draw (Graphics g)
{
// declare two arrays for X & Y coordinates of Diamond
int iPointsX[] = new int [4];
int iPointsY[] = new int [4];
// calculate points on diamond & store in the arrays
iPointsX [0] = cx - width / 2;
iPointsY [0] = cy;
iPointsX [1] = cx;
iPointsY [1] = cy - height / 2;
iPointsX [2] = cx + width / 2;
iPointsY [2] = cy;
iPointsX [3] = cx;
iPointsY [3] = cy + height / 2;
// draw the diamond using methods available from the Console object (c)
g.setColor (iColor);
if (isFilled)
{
g.fillPolygon (iPointsX, iPointsY, 4);
}
else
{
g.drawPolygon (iPointsX, iPointsY, 4);
}
}
}