-
Notifications
You must be signed in to change notification settings - Fork 0
/
Box.java
101 lines (80 loc) · 2.14 KB
/
Box.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
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
/**
* Yuki Tetsuka
* <p>
* Project: DrawJava
* Description: A simple drawing application in Java.
* <p>
* Copyright (c) 2023 Yuki Tetsuka. All rights reserved.
* See the project repository at: https://github.com/ponstream24/DrawJava
*/
package enshuReport2_2023;
import java.awt.*;
public class Box extends Figure {
boolean isEraser = false;
public Box(boolean isEraser) {
// 初期値を白。10にする。
this.color = Color.BLACK;
this.isFill = false;
this.isEraser = isEraser;
}
public Box() {
// 初期値を白。10にする。
this.color = Color.BLACK;
this.isFill = false;
}
@Override
public void paint(Graphics g) {
if (isEraser) {
g.setColor(Color.WHITE);
} else {
g.setColor(this.color);
}
if (this.isFill) {
if (w >= 0 && h >= 0) {
g.fillRect(x, y, w, h);
} else if (w < 0 && h >= 0) {
g.fillRect(x + w, y, -w, h);
} else if (w >= 0) {
g.fillRect(x, y + h, w, -h);
} else {
g.fillRect(x + w, y + h, -w, -h);
}
} else {
if (w >= 0 && h >= 0) {
g.drawRect(x, y, w, h);
} else if (w < 0 && h >= 0) {
g.drawRect(x + w, y, -w, h);
} else if (w >= 0) {
g.drawRect(x, y + h, w, -h);
} else {
g.drawRect(x + w, y + h, -w, -h);
}
}
}
@Override
public void paintLine(Graphics g, int x, int y) {
if (isEraser) {
g.setColor(Color.WHITE);
} else {
g.setColor(this.color);
}
g.fillRect(x - w / 2, y - h / 2, w, h);
}
@Override
public void move(int dx, int dy) {
x += dx;
y += dy;
}
@Override
public Box clone() {
Box box = new Box();
box.color = this.color;
box.isEraser = this.isEraser;
box.isFill = this.isFill;
box.x = this.x;
box.y = this.y;
box.w = this.w;
box.h = this.h;
return box;
}
}