HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 80 Inheritance or Subclassing

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * Important Information in IMAGE

We can define a new class mRectangle that extends mPoint where (x,y,color) from mPoint are lower left hand corner/color and we add width and height
public class mRectangle extends mPoint {
  • int w, h;
  • public mRectangle(int _x, int _y, int _w, int _h) {
    • super(_x, _y); /* call mPoint's constructor */
    • w = _w;
    • h = _h;
  • } /* End mRectangle Constructor */
/* overwrite the mPoint's checkBoundry method */
  • public void checkBoundry(Rectangle rect) {
    • int nx = x+dx;
    • int ny = y+dy;
    • if ( (nx < rect.x) || (nx+w >= rect.x+rect.width) ) dx = -dx;
    • if ( (ny < rect.y) || (ny+h >= rect.y+rect.height) ) dy = -dy;
  • }
  • public void paint(Graphics g) { /* Override mPoint Method */
    • g.setColor(color);
    • g.drawRect(x, y, w, h);
  • }
}



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 Tue Feb 18 1997