This program draws crosshairs that intersect at the current mouse location. It also displays the coordinates of the mouse.
import objectdraw.*;
import java.awt.*;
public class MysteryProgram extends WindowController {
private static final int HORIZ_OFFSET = 15;
private static final int VERT_OFFSET = 2;
private Line vert;
private Line horiz;
private Text label;
public void begin()
{
new VisibleImage( getImage("pic.jpg"),0, 0, canvas);
vert = new Line (0, 0, 0, 0, canvas);
horiz = new Line (0, 0, 0, 0, canvas);
label = new Text("", 0, 0, canvas);
vert.setColor (Color.YELLOW);
horiz.setColor (Color.YELLOW);
label.setColor (Color.YELLOW);
}
public void onMouseMove(Location point) {
vert.setEndPoints(point.getX(), 0, point.getX(), canvas.getHeight());
horiz.setEndPoints( 0, point.getY(), canvas.getWidth(), point.getY());
label.setText("[" + point.getX() + "," + point.getY() + "]");
label.moveTo(point.getX() + HORIZ_OFFSET, point.getY() + VERT_OFFSET);
}
}