import java.awt.*;

public class RectFigure extends Figure {

  int x,y;           // the coordinates of the upper-left corner
  int width,height;  // the size of the rectangle
  boolean filled;
  Color c;

  public RectFigure (int x1, int y1, int x2, int y2, boolean f, Color cVal) {
    width = Math.abs(x2-x1);
    height = Math.abs(y2-y1);
    x = Math.min(x1,x2);
    y = Math.min(y1,y2);
    filled = f;
    c = cVal;
  }

  public void draw (Graphics g) {
    g.setColor(c);
    if (filled) g.fillRect(x, y, width, height);
    else        g.drawRect(x, y, width, height);
  }

  public boolean inFigure (int x0, int y0) {
    return x <= x0 && x0 <= x+width && y <= y0 && y0 <= y+height;
  }
  
  public void drag (int dx, int dy) {
    x += dx; y += dy;
  }
}
