import objectdraw.*; // Enables a user to draw crosshairs that can be positioned // using the mouse. Draws an initial set of centered crosshairs // at the start of the program. public class Crosshairs extends FrameWindowController { // the crosshair lines private Line horiz; private Line vert; // draw a set of crosshairs centered in the window public void begin() { new Line(0, canvas.getHeight() / 2, canvas.getWidth(), canvas.getHeight() / 2, canvas); new Line(canvas.getWidth() / 2, 0, canvas.getWidth() / 2, canvas.getHeight(), canvas); } // display the crosshairs as soon as the mouse button is pressed public void onMousePress(Location point) { // create the lines for the crosshairs horiz = new Line(0, point.getY(), canvas.getWidth(), point.getY(), canvas); vert = new Line(point.getX(), 0, point.getX(), canvas.getHeight(), canvas); } // move the crosshairs as the mouse is dragged about the window public void onMouseDrag(Location point) { // reposition the crosshair lines horiz.removeFromCanvas(); vert.removeFromCanvas(); horiz = new Line(0, point.getY(), canvas.getWidth(), point.getY(), canvas); vert = new Line(point.getX(), 0, point.getX(), canvas.getHeight(), canvas); } }