/** * ClickCounter * counts how often the user clicks the mouse * * @author Kim Bruce * @version spring 2006 */ import objectdraw.*; import java.awt.*; // program that displays how many times the mouse has been clicked public class ClickCounter extends WindowController{ // Location of the display private static final int DISPLAY_X = 150; private static final int DISPLAY_Y = 200; // the Text object which displays the count private Text display; // the number of clicks private int count; // initialize the counter and the text message public void begin() { count = 0; display = new Text("Click count = 0", DISPLAY_X, DISPLAY_Y, canvas); } // increment the counter and update the text public void onMouseClick(Location point) { count = count + 1; display.setText("Click count = " + count ); } }