Source of HouseShape.java


  1: import java.awt.*;
  2: import java.awt.geom.*;

  4: /**
  5:    A house shape.
  6: */
  7: public class HouseShape extends CompoundShape
  8: {
  9:    /**
 10:       Constructs a house shape.
 11:       @param x the left of the bounding rectangle
 12:       @param y the top of the bounding rectangle
 13:       @param width the width of the bounding rectangle
 14:    */
 15:    public HouseShape(int x, int y, int width)
 16:    {
 17:       Rectangle2D.Double base 
 18:          = new Rectangle2D.Double(x, y + width, width, width);

 20:       // The left bottom of the roof
 21:       Point2D.Double r1
 22:          = new Point2D.Double(x, y + width);
 23:       // The top of the roof
 24:       Point2D.Double r2
 25:          = new Point2D.Double(x + width / 2, y);
 26:       // The right bottom of the roof
 27:       Point2D.Double r3
 28:          = new Point2D.Double(x + width, y + width);

 30:       Line2D.Double roofLeft
 31:          = new Line2D.Double(r1, r2);
 32:       Line2D.Double roofRight
 33:          = new Line2D.Double(r2, r3);

 35:       add(base);
 36:       add(roofLeft);
 37:       add(roofRight);
 38:    }
 39: }