import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; /** * @author Prof. Wittie CS 203, Fall 2009 */ /** * Bacon is a pizza topping. A bacon bit has height 20 and width 40 when drawn. */ public class Bacon { private double xCoord; private double yCoord; // Creates a single bacon bit. The top left corner of // the bounding box is at (xCoord, yCoord). /** * Creates a single bacon bit * * @param xCoord * x coordinate of the upper left corner of the bounding box. * @param yCoord * y coordinate of the upper left corner of the bounding box. */ public Bacon(double xCoord, double yCoord) { this.xCoord = xCoord; this.yCoord = yCoord; } /** * Draws the bacon * * @param g2 * the graphics context. */ public void draw(Graphics2D g2) { Rectangle2D.Double top = new Rectangle2D.Double(xCoord, yCoord, 40, 10); Rectangle2D.Double bottom = new Rectangle2D.Double(xCoord, yCoord + 10, 40, 10); // http://www.tayloredmktg.com/rgb/#PI g2.setColor(new Color(233, 150, 122)); // dark salmon g2.fill(bottom); g2.setColor(new Color(245, 245, 220)); // beige g2.fill(top); // The outline Rectangle2D.Double b = new Rectangle2D.Double(xCoord, yCoord, 40, 20); g2.setColor(Color.BLACK); g2.draw(b); } }