// // FILE: BoundedBall // AUTHOR: Eugene Wallingford // DATE: 2012/10/02 // COMMENT: a Ball that bounces off the sides of its Frame // implemented during Session 13 // // MODIFIED: 2012/10/20 -- Eugene Wallingford // CHANGE: Changed the deltaX and deltaY variables to be doubles, // to match the modified Ball class. // // MODIFIED: 2012/10/31 -- Eugene Wallingford // CHANGE: Added accessor for subclass. // import java.awt.Frame; public class BoundedBall extends Ball { private Frame myWorld; public BoundedBall( int x, int y, int r, double dx, double dy, Frame f ) { super( x, y, r, dx, dy ); myWorld = f; } public void move() { super.move(); int maxWidth = myWorld.getWidth(); if (( x() < 0 ) || ( x() > maxWidth )) reverseDeltaX(); int maxHeight = myWorld.getHeight(); if (( y() < 0 ) || ( y() > maxHeight )) reverseDeltaY(); } protected Frame frame() { return myWorld; } }