/* File: mRectangle.java */ import java.awt.*; public class mRectangle extends mPoint { // Instance variables: protected int w, h; // width and height // Constructor: public mRectangle( int new_x, int new_y, int new_w, int new_h ) { // Invoke the constructor of the superclass mPoint: super( new_x, new_y ); w = new_w; h = new_h; } // Implement mPoint.paint( Graphics ): public void paint( Graphics g ) { g.setColor( color ); g.fillRect( x, y, w, h ); } // Implement mPoint.checkBoundary( Rectangle ): public void checkBoundary( Rectangle r ) { // Calculate new location: int nx = x + dx, ny = y + dy; // Check if new location out of bounds: if ( (nx < r.x) || (nx + w > r.x + r.width) ) dx = -dx; if ( (ny < r.y) || (ny + h > r.y + r.height) ) dy = -dy; } // Implement mPoint.isInside( int, int ): public boolean isInside( int some_x, int some_y ) { Rectangle r = new Rectangle( x, y, w, h ); return r.contains( some_x, some_y ); } } // end of mRectangle class