- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
Latest commit
136 lines (116 loc) · 4.25 KB
/
Copy pathShape.java
File metadata and controls
136 lines (116 loc) · 4.25 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Name: Thomas Cheng
*
* Date: May 2, 2018
*
* Dsscription: This is the abstract Shape class.
*/
importjava.awt.Color;
importjava.awt.Graphics;
importjava.awt.Graphics2D;
importjava.awt.GradientPaint;
importjava.awt.BasicStroke;
abstractpublicclassShape{
// creating the private variables for this class
privateintx1;
privateinty1;
privateintx2;
privateinty2;
privateColorcolourOne;
privateColorcolourTwo;
privatebooleanisGradient;
privatedoublelineSize;
/* This is the constructor method for the Shape class. This method accepts 5 parameters. x1, y1, x2, y2,
* representing the starting and ending coordinates of the shape respectively, and a reference to a Color object.
*/
publicShape( intx1, inty1, intx2, inty2, ColorcolourOne, ColorcolourTwo, BooleanisGradient, doublelineSize){
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.colourOne = colourOne;
this.colourTwo = colourTwo;
this.isGradient = isGradient;
this.lineSize = lineSize;
}
/* This is the accessor method that returns the x1 value of the shape. This method accepts no values.
*/
publicintgetX1(){
returnx1;
}
/* This is the accessor method that returns the x2 value of the shape. This method accepts no values.
*/
publicintgetX2(){
returnx2;
}
/* This is the accessor method that returns the y1 value of the shape. This method accepts no values.
*/
publicintgetY1(){
returny1;
}
/* This is the accessor method that returns the y2 value of the shape. This method accepts no values.
*/
publicintgetY2(){
returny2;
}
/* This is the mutator method that changes the x1 value. This method accepts 1 parameter: an int value representing
* the object's x1 value. This method returns no values.
*/
publicvoidsetX1 (intxValue){
x1 = xValue;
}
/* This is the mutator method that changes the y1 value. This method accepts 1 parameter: an int value representing
* the object's y1 value. This method returns no values.
*/
publicvoidsetY1 (intyValue){
y1 = yValue;
}
/* This is the mutator method that changes the x2 value. This method accepts 1 parameter: an int value representing
* the object's x2 value. This method returns no values.
*/
publicvoidsetX2 (intxValue){
x2 = xValue;
}
/* This is the mutator method that changes the y2 value. This method accepts 1 parameter: an int value representing
* the object's y2 value. This method returns no values.
*/
publicvoidsetY2 (intyValue){
y2 = yValue;
}
/* This is the mutator method that changes the shape's colour. This method accepts 1 parameter: a reference to a
* Color object. This method returns no values.
*/
publicvoidsetColourOne( ColorcolourOne ){
this.colourOne = colourOne;
}
/* This is the accessor method that returns the colour of the shape. This method accepts no values.
*/
publicColorgetColourOne(){
returncolourOne;
}
publicvoidsetColourTwo( ColorcolourTwo ){
this.colourTwo = colourTwo;
}
publicColorgetColourTwo( ColorcolourTwo ){
returncolourTwo;
}
publicvoidsetIsGradient ( booleanisGradient ) {
this.isGradient = isGradient;
}
publicbooleangetIsGradient(){
returnisGradient;
}
publicGraphics2DconvertGraphics(Graphicsg){
Graphics2Dg2d = (Graphics2D) g;
g2d.setStroke( newBasicStroke( (float)lineSize ) );
if ( !isGradient )
colourTwo = colourOne;
GradientPaintgradient = newGradientPaint(x1, y1, colourOne, x2, y2, colourTwo);
g2d.setPaint(gradient);
returng2d;
}
/* This is the abstract draw method. This method accepts 1 parameter: a reference to a Graphics object. This method
* returns no values.
*/
abstractpublicvoiddraw( Graphicsg );
}