-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamondClass.java
More file actions
95 lines (79 loc) · 1.9 KB
/
Copy pathDiamondClass.java
File metadata and controls
95 lines (79 loc) · 1.9 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// The DiamondClass Class
// Second in a series of demonstration programs for introducing Java
//import hsa.Console;
import java.awt.*;
class DiamondClass extends SuitClass
{
// global variables for this class
// encapsulated data
protected boolean filled = true;
public DiamondClass ()
{
}
public DiamondClass (int xNew, int yNew, int widthNew, Color colourNew)
{
x = xNew;
y = yNew;
setWidth (widthNew);
setColour (colourNew);
}
// communicator methods
public void setIsFilled (boolean newfilled)
{
filled = newfilled;
}
public boolean getIsFilled ()
{
return filled;
}
/*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] = x - (width / 2);
iPointsY [0] = y;
iPointsX [1] = x;
iPointsY [1] = y - (height / 2);
iPointsX [2] = x + (width / 2);
iPointsY [2] = y;
iPointsX [3] = x;
iPointsY [3] = y + (height / 2);
// draw the diamond using methods available from the Console object (c)
c.setColor (colour);
if (filled)
{
c.fillPolygon (iPointsX, iPointsY, 4);
}
else
{
c.drawPolygon (iPointsX, iPointsY, 4);
}
}*/
public void draw (Graphics 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] = x - (width / 2);
iPointsY [0] = y;
iPointsX [1] = x;
iPointsY [1] = y - (height / 2);
iPointsX [2] = x + (width / 2);
iPointsY [2] = y;
iPointsX [3] = x;
iPointsY [3] = y + (height / 2);
// draw the diamond using methods available from the Console object (c)
c.setColor (colour);
if (filled)
{
c.fillPolygon (iPointsX, iPointsY, 4);
}
else
{
c.drawPolygon (iPointsX, iPointsY, 4);
}
}
}