import objectdraw.*; // This program shows how one might enable a user to pinpoint the coordinates // of a particular spot in a digital image by providing crosshairs that can // be positioned using the mouse and displaying the numeric coordinates as // the crosshairs move. public class Crosshairs extends FrameWindowController { // the crosshair lines private Line vert, horiz; // display the crosshairs as soon as the mouse button is pressed public void onMousePress(Location point) { // create the lines for the crosshairs vert = new Line(point.getX(), 0, point.getX(), canvas.getHeight(), canvas); horiz = new Line(0, point.getY(), canvas.getWidth(), point.getY(), canvas); } // remove the crosshairs as soon as the mouse is released. public void onMouseRelease(Location point){ vert.removeFromCanvas(); horiz.removeFromCanvas(); } // move the crosshairs as the mouse is dragged about the window public void onMouseDrag(Location point) { // reposition the crosshair lines vert.setEndPoints(point.getX(), 0, point.getX(), canvas.getHeight()); horiz.setEndPoints(0, point.getY(), canvas.getWidth(), point.getY()); } }