// // FILE: Disk.java // AUTHOR: Eugene Wallingford // DATE: 2012/09/18 // COMMENT: extracted from Ball class by Tim Budd in the textbook // Understanding Object-Oriented Programming with Java // // MODIFIED: 2012/10/02 -- Eugene Wallingford // CHANGE: added x() and y() accessors for subclass use // // MODIFIED: 2012/10/11 -- Eugene Wallingford // CHANGE: added darker() and brighter() methods for subclass use // import java.awt.Color; import java.awt.Graphics; public class Disk { private int x; private int y; private int radius; private Color color; public Disk( int x, int y, int r ) { this.x = x; this.y = y; radius = r; color = Color.blue; } public void paint( Graphics g ) { g.setColor( color ); g.fillOval( x, y, radius*2, radius*2 ); } protected void moveBy( int deltaX, int deltaY ) { x += deltaX; y += deltaY; } protected int x() { return x; } protected int y() { return y; } protected void darker() { color = color.darker(); } protected void brighter() { color = color.brighter(); } // accessors for subclasses protected void become( Color newColor ) { color = newColor; } }