blob: 21d6e1cf6c47cb8688a3729ea4127493977b7822 (
plain)
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
|
package sample.duplicate;
import java.awt.Graphics;
import java.awt.Color;
public class Ball {
private int x, y;
private Color color;
private int radius = 30;
private boolean isBackup = false;
public Ball(int x, int y) {
move(x, y);
changeColor(Color.orange);
}
// This constructor is for a backup object.
public Ball(Ball b) {
isBackup = true;
}
// Adjust the position so that the backup object is visible.
private void adjust() {
if (isBackup) {
this.x += 50;
this.y += 50;
}
}
public void paint(Graphics g) {
g.setColor(color);
g.fillOval(x, y, radius, radius);
}
public void move(int x, int y) {
this.x = x;
this.y = y;
adjust();
}
public void changeColor(Color color) {
this.color = color;
}
}
|