-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquare.java
49 lines (38 loc) · 989 Bytes
/
Square.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
import java.awt.Graphics;
import java.awt.Color;
public class Square {
private Color color;
private int x, y;
// Constructor
public Square(Color color) {
this.color = color;
}
public Square(Color color, int x, int y) {
this.color = color;
this.x = x;
this.y = y;
}
public void drawSquare(Graphics g, int x, int y) {
// Draw one square filled with the color indicated by the object's instance variable at location (x, y).
g.setColor(color);
g.fillRect(x, y, 40, 40);
this.x = x;
this.y = y;
}
public void setColor(Color selectedColor) {
// Sets the Color instance variable to a new color.
this.color = selectedColor;
}
public void returnColor() {
System.out.println(color);
}
public Color getColor() {
return color;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}