Computer Science 120
Introduction to Programming
Spring 2012, Siena College
ClickCounter Demo
A working demo of ClickCounter will appear below. Click inside the applet to interact with it.
ClickCounter BlueJ Project
Click here to download a BlueJ project for ClickCounter.
ClickCounter Source Code
The Java source code for ClickCounter is below. Click on a file name to download it.
import objectdraw.*; import java.awt.*; /* * Example ClickCounter * Program that displays how many times the mouse has been clicked. * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * Based on example from Williams College, CSCI 134 * * $Id: ClickCounter.java 1501 2011-01-24 20:48:50Z terescoj $ */ 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); } }