1 /* mRectangle.java */ 2 3 import java.awt.*; 4 5 public class mRectangle extends mPoint { 6 int w, h; 7 public mRectangle(int _x, int _y, int _w, int _h) { 8 /* call mPoint's constructor */ 9 super(_x, _y); 10 /* initial w and h */ 11 w = _w; 12 h = _h; 13 } 14 /* check if position inside object */ 15 public boolean isInside(int _x, int _y) { 16 return (x <= _x) && (_x < x+w) && (y <= _y) && (_y < y+h); 17 } 18 public void paint(Graphics g) { 19 /* draw rectangle */ 20 g.setColor(color); 21 g.drawRect(x, y, w, h); 22 } 23 }