-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyBoundedShape.java
More file actions
111 lines (93 loc) · 2.33 KB
/
Copy pathMyBoundedShape.java
File metadata and controls
111 lines (93 loc) · 2.33 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
import java.awt.Color;
import java.awt.Graphics;
/**
* this class Declaration of class MyBoundedShape.
*/
public class MyBoundedShape extends MyShape
{
private boolean filled; // whether this shape is filled
/**
* MyBoundedShape constructor initializes private vars with default values
*/
public MyBoundedShape()
{
super();
}
/**
* MyBoundedShape constructor with input values
*@param x1 x coordinate of first endpoint
*@param y1 y coordinate of first endpoint
*@param x2 x coordinate of second endpoint
*@param y2 y coordinate of second endpoint
*@param myColor the color of the shape
*@param filled if the shape is filled
*/
public MyBoundedShape(int x1, int y1, int x2, int y2,
Color myColor, boolean filled)
{
super(x1,y1,x2,y2,myColor);
this.filled = filled;
}
/**
* isFilled method determines whether this shape is filled
* @return if shape is filled
*/
public boolean isFilled()
{
return filled;
}
/**
* setFilled method sets whether this shape is filled
* @param filled if shape is filled
*/
public void setFilled(boolean filled)
{
this.filled = filled;
}
/**
* getUpperLeftX method get upper left x coordinate
* @return upper left x coordinate
*/
public int getUpperLeftX()
{
return Math.min(super.getX1(), super.getX2());
}
/**
* getUpperLeftY method get upper left x coordinate
* @return upper left x coordinate
*/
public int getUpperLeftY()
{
return Math.min(super.getY1(), super.getY2());
}
/**
* getWidth method get shape width
* @return shape width
*/
public int getWidth()
{
return Math.abs(super.getX2() - super.getX1());
}
/**
* getHeight method get shape height
* @return shape height
*/
public int getHeight()
{
return Math.abs(super.getY2() - super.getY1());
}
/**
* draw method draws an rectangle in the specified color
* @param g Graphics shape
*/
public void draw(Graphics g)
{
g.setColor(super.getColor());
if (isFilled())
g.fillRect(getUpperLeftX(), getUpperLeftY(),
getWidth(), getHeight());
else
g.drawRect(getUpperLeftX(), getUpperLeftY(),
getWidth(), getHeight());
}
} // end class MyBoundedShape