import objectdraw.*; import java.awt.Color; // drawing a road with some lane markers public class Lanes extends FrameWindowController { // number and size of lanes private static final int LANES = 2; private static final double LANEWIDTH = 50; // position and size of road private static final double ROADLEFT = 100; private static final double ROADWIDTH = LANES*LANEWIDTH; // position and dimensions of white lines private static final double LINESWIDTH = 10; private static final double LINESLENGTH = 40; private static final double LINESLEFT = ROADLEFT + LANEWIDTH - LINESWIDTH / 2; private static final double LINESPACING= 1.7 * LINESLENGTH; // draw the initial roadway public void begin() { new FilledRect(ROADLEFT, 0, ROADWIDTH, canvas.getHeight(), canvas); } // draw the next lane marker when the mouse is pressed public void onMousePress(Location point) { // the y coordinate of the next lane marker to draw double nextLineTop = 0; // have we drawn all the lines? while (nextLineTop < canvas.getHeight()) { // draw the next line FilledRect nextLine = new FilledRect(LINESLEFT, nextLineTop, LINESWIDTH, LINESLENGTH, canvas); nextLine.setColor(Color.WHITE); // update the Y coordinate for the next line nextLineTop = nextLineTop + LINESPACING; } } // clear screen and redraw roadway public void onMouseExit(Location point) { canvas.clear(); new FilledRect(ROADLEFT, 0, ROADWIDTH, canvas.getHeight(), canvas); } }