01: package sample.duplicate;
02:
03: import java.awt.Graphics;
04: import java.awt.Color;
05:
06: public class Ball {
07: private int x, y;
08: private Color color;
09: private int radius = 30;
10: private boolean isBackup = false;
11:
12: public Ball(int x, int y) {
13: move(x, y);
14: changeColor(Color.orange);
15: }
16:
17: // This constructor is for a backup object.
18: public Ball(Ball b) {
19: isBackup = true;
20: }
21:
22: // Adjust the position so that the backup object is visible.
23: private void adjust() {
24: if (isBackup) {
25: this .x += 50;
26: this .y += 50;
27: }
28: }
29:
30: public void paint(Graphics g) {
31: g.setColor(color);
32: g.fillOval(x, y, radius, radius);
33: }
34:
35: public void move(int x, int y) {
36: this .x = x;
37: this .y = y;
38: adjust();
39: }
40:
41: public void changeColor(Color color) {
42: this.color = color;
43: }
44: }
|