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; public void begin() { new FilledRect(ROADLEFT, 0, ROADWIDTH, canvas.getHeight(), canvas); } // redraw lane separators when mouse is clicked public void onMouseClick(Location point) { double lineTop = 0; while (lineTop < canvas.getHeight()) { FilledRect nextLine = new FilledRect(LINESLEFT, lineTop, LINESWIDTH, LINESLENGTH, canvas); nextLine.setColor(Color.WHITE); lineTop = lineTop + LINESPACING; } } // clear screen and redraw roadbed public void onMouseExit(Location point) { canvas.clear(); new FilledRect(ROADLEFT, 0, ROADWIDTH, canvas.getHeight(), canvas); } }