import java.awt.*;
/**
 * This is an example of the kind of command that can be
 * executed by an instance of the TurtleCanvas class.
 * @author David Matuszek
 * @version March 16, 2006
 *
 */
class DrawLineCommand implements TurtleCommand {
    int x1, y1, x2, y2;
    
    /**
     * This is an example of a constructor for a subclass of
     * TurtleCommand. The constructor should typically take whatever
     * arguments are needed for the command (this particular
     * example takes three) and just saves them in instance
     * variables for later use.
     */
    DrawLineCommand(double x1, double y1, double x2, double y2) {
        this.x1 = (int) Math.round(x1);
        this.y1 = (int) Math.round(y1);
        this.x2 = (int) Math.round(x2);
        this.y2 = (int) Math.round(y2);
    }
    
    /**
     * Implements this command on the given Graphics. In this
     * example, the method just draws a string on the Graphics;
     * the particular string, as well as the particular x-y
     * coordinates, were determined when this DrawStringCommand
     * was created.<p>
     * 
     * Note that not all commands need to draw something. For
     * instance, some commands may change the color to be used,
     * or otherwise change the state of the Graphics object.
     * Some commands might even ignore the Graphics parameter
     * entirely, and just change the state of the turtle.
     * 
     * @param g The graphics on which to do the drawing.
     */
    public void execute(Graphics g) {
        g.drawLine(x1, y1, x2, y2);
    }
}
