- import objectdraw.*;
- import java.awt.*;
- /* A program that draws perpendicular lines that move
- so that they always intersect at the mouse's current
- position */
- public class CrossHairs extends WindowController {
- private int canvasWidth, canvasHeight;
- // Initially center the lines
- public void begin() {
- canvasWidth = canvas.getWidth();
- canvasHeight = canvas.getHeight();
- canvas);
- canvas);
- }
- // move the lines so that they intersect at the mouse
- public void onMouseDrag(Location point) {
- vert.setEndPoints(point.getX(), 0, point.getX(), canvasHeight);
- horiz.setEndPoints(0, point.getY(), canvasWidth, point.getY());
- }
- }
Raw Paste