/** * BaseballField.java * * @author David Tran * @version 1.0 */ package background; import java.awt.Graphics2D; import java.awt.Color; import java.awt.Stroke; import java.awt.BasicStroke; import java.awt.Point; import java.awt.geom.*; /** * A background representing a baseball field. */ public class BaseballField extends Background { /** * Initialize attributes for this BaseballField * * @param x x-coordinate of this BaseballField (leftmost position of background) * @param y y-coordinate of this BaseballField (uppermost position of background) * @param w width of this BaseballField * @param h height of this BaseballField */ public BaseballField(double x, double y, double w, double h) { super(x, y, w, h); super.externalName = "Baseball-Field"; } /** * Use the graphics system to draw the shapes representing this BaseballField * * @param g the graphics system to use */ public void draw(Graphics2D g) { // Draw outfield g.setPaint((Color.GREEN).darker()); g.fill(new Rectangle2D.Double(xCoor, yCoor, width, height)); // Draw the infield // RGB values for brown: Red:[222] Green:[184] Blue[135] g.setPaint(new Color(222, 184, 135)); g.fill(new Rectangle2D.Double(xCoor, yCoor, width/2, height/2)); g.setPaint((Color.GREEN).darker()); g.fill(new Rectangle2D.Double(xCoor+4, yCoor+4, width/2-16, height/2-16)); g.setPaint(new Color(222, 184, 135)); g.fill(new Ellipse2D.Double(xCoor+width/6, yCoor+height/6, 10, 10)); // Draw out-of-bounds-lines Stroke oldStroke = g.getStroke(); g.setPaint(Color.WHITE); g.setStroke(new BasicStroke(1.5f)); g.draw(new Line2D.Double(xCoor, yCoor, xCoor+width, yCoor)); g.draw(new Line2D.Double(xCoor, yCoor, xCoor, yCoor+height)); g.setStroke(oldStroke); } }