/* mRectangle.java */ import java.awt.*; public class mRectangle extends mPoint { int w, h; public mRectangle(int _x, int _y, int _w, int _h) { /* call mPoint's constructor */ super(_x, _y); /* initial w and h */ w = _w; h = _h; } public void checkBoundry(Rectangle rect) { /* overwrite the mPoint's checkBoundry */ /* the rectangle's checkBoundry is different */ int nx = x+dx; int ny = y+dy; int nw = w+dx; int nh = h+dy; if ( (nx < rect.x) || (nx+nw >= rect.x+rect.width) ) dx = -dx; if ( (ny < rect.y) || (ny+nh >= rect.y+rect.height) ) dy = -dy; } public void paint(Graphics g) { /* draw rectangle */ g.setColor(color); g.drawRect(x, y, w, h); } public void new_paint(Graphics g) { /* draw rectangle */ g.setColor(color); w +=dx; h +=dy; g.drawRect(x, y, w, h); } }