import java.awt.*; import java.awt.geom.*; import javax.swing.JComponent; /** * @author Prof. Wittie * CS 203, Fall 2009 */ /** * A vertical ruler with markings every 20 units. */ public class Ruler { private double height; private double xCoord; private double yCoord; /** * The ruler has these x and y coordinates at the top left corner * of its bounding box and has the given height. * * @param xCoord * x coordinate of the bounding box * @param yCoord * y coordinate of the bounding box * @param height * height of the ruler */ public Ruler(double xCoord, double yCoord, double height) { this.xCoord = xCoord; this.yCoord = yCoord; this.height = height; } /** * Draw the ruler at the current x and y coordinates * * @param g2 * the graphics context */ public void draw(Graphics g) { Graphics2D g2 = (Graphics2D) g; Line2D.Double line = new Line2D.Double(xCoord, yCoord, xCoord, yCoord + height); g2.setColor(Color.BLUE); g2.draw(line); double i; for(i=yCoord; i