1 package sample.duplicate; 2 3 import java.awt.Graphics; 4 import java.awt.Color; 5 6 public class Ball { 7 private int x, y; 8 private Color color; 9 private int radius = 30; 10 private boolean isBackup = false; 11 Ball(int x, int y)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. Ball(Ball b)18 public Ball(Ball b) { 19 isBackup = true; 20 } 21 22 // Adjust the position so that the backup object is visible. adjust()23 private void adjust() { 24 if (isBackup) { 25 this.x += 50; 26 this.y += 50; 27 } 28 } 29 paint(Graphics g)30 public void paint(Graphics g) { 31 g.setColor(color); 32 g.fillOval(x, y, radius, radius); 33 } 34 move(int x, int y)35 public void move(int x, int y) { 36 this.x = x; 37 this.y = y; 38 adjust(); 39 } 40 changeColor(Color color)41 public void changeColor(Color color) { 42 this.color = color; 43 } 44 } 45