// AddLine.java // Command class to add a Segment object to the drawing. // Written by THC for CS 5 Lab Assignment 3. import java.awt.*; public class AddLine extends Command { private int x1, y1; // starting endpoint for the Segment // When the mouse is pressed, remember its position, create a new Segment // with coincident endpoints, and add the new Segment to the front of the // drawing. public void executePress(Point p, Drawing dwg) { x1 = p.x; y1 = p.y; Segment s = new Segment(x1, y1, x1, y1, dwg.getColor()); dwg.add(s); } // When the mouse is dragged, make a new Segment with the original press // position and the current mouse position, and have this new Segment // replace the one that is currently at the front of the drawing. public void executeDrag(Point p, Drawing dwg) { Segment s = new Segment(x1, y1, p.x, p.y, dwg.getColor()); dwg.replaceFront(s); } }