import java.awt.Color; import java.awt.Graphics; public class DeceleratingBall extends Ball { private Ball workerBall; public DeceleratingBall( Ball aBall ) { super(); workerBall = aBall; } public void move() { workerBall.move(); workerBall.adjustSpeedBy( -0.01 ); } public void paint( Graphics g ) { workerBall.paint( g ); } // --- We must delegate protected messages, too. protected void adjustSpeedBy( double ddx, double ddy ) { workerBall.adjustSpeedBy( ddx, ddy ); } protected void adjustSpeedBy( double factor ) { workerBall.adjustSpeedBy( factor ); } protected void reverseDeltaX() { workerBall.reverseDeltaX(); } protected void reverseDeltaY() { workerBall.reverseDeltaY(); } protected void moveBy( int deltaX, int deltaY ) { workerBall.moveBy( deltaX, deltaY ); } protected int x() { return workerBall.x(); } protected int y() { return workerBall.y(); } protected Color color() { return workerBall.color(); } protected void setColor( Color c ) { workerBall.setColor( c ); } }