-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shape.java
75 lines (66 loc) · 1.66 KB
/
Shape.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
/**
* Baseclass for Triangle, Square, Circle
*
* @author
* @version
*/
public abstract class Shape extends Point
{
// instance variables - replace the example below with your own
private String color;
private boolean isVisible;
/**
* Constructor for objects of class Shape
*/
public Shape(double xPosition,double yPosition,String color,boolean isVisible)
{
super(xPosition, yPosition);
this.color = color;
this.isVisible = isVisible;
}
/**
* Erase the picture from the screen.
*/
public void erase() {
if(isVisible) {
Canvas canvas = Canvas.getCanvas();
canvas.erase(this);
}
}
public String getColor() {
return color;
}
public boolean isVisible() {
return isVisible;
}
/**
* Make this square visible. If it was already visible, do nothing.
*/
public void makeVisible() {
isVisible = true;
draw();
}
/**
* Make this square invisible. If it was already invisible, do nothing.
*/
public void makeInvisible() {
erase();
isVisible = false;
}
/**
* Change the color. Valid colors are "red", "yellow", "blue", "green",
* "magenta" and "black".
*/
public void changeColor(String newColor) {
color = newColor;
draw();
}
/**
* Move the figure by (deltaX,deltaY) pixels.
*/
public void move(double deltaX,double deltaY) {
erase();
super.move(deltaX, deltaY);
draw();
}
}