Basic HTML version of Foils prepared 13 July 98

Foil 76 The checkBounds Method

From Java Academy II:Advanced Java NPAC/ECS Java Academy -- February to April 98. by Tom Scavo


1 This ensures the square stays within r: private void checkBounds( Rectangle r ) { // Compute dimensions of the square: Rectangle bb = square.getBounds(); int w = bb.width, h = bb.height; int new_x = bb.x + dx, new_y = bb.y + dy; // If square is out of bounds, reverse direction: if ( ( new_x < r.x ) || ( new_x + w > r.x + r.width ) ) dx *= -1; if ( ( new_y < r.y ) || ( new_y + h > r.y + r.height ) ) dy *= -1; }
2 Note: The method refers to java.awt.Rectangle!

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998