Computer Science 252
Problem Solving with Java
Spring 2014, The College of Saint Rose
StaticCount Demo
A working demo of StaticCount will appear below. Click inside the applet to interact with it.
StaticCount BlueJ Project
Click here to download a BlueJ project for StaticCount.
StaticCount Source Code
The Java source code for StaticCount is below. Click on a file name to download it.
import objectdraw.*;
import java.awt.*;
/*
* Example StaticCount
*
* Jim Teresco, Siena College, CSIS 120, Spring 2012
*
* $Id: StaticCount.java 2218 2013-10-18 14:06:39Z terescoj $
*/
public class StaticCount extends WindowController {
public void onMousePress(Location point) {
new NumberInCircle(point, canvas);
}
}
import objectdraw.*;
/**
* A simple class to create a number inside a circle on the canvas,
* demonstrating a class variable.
*
* Jim Teresco, The College of Saint Rose, Spring 2014, CSC 252
*
* $Id: NumberInCircle.java 2351 2014-05-01 01:51:25Z terescoj $
*/
public class NumberInCircle
{
private static final int SIZE = 50;
// a class variable! Just one copy of this is
// shared among all instances of the class we ever
// will create
private static int nextNum = 0;
public NumberInCircle(Location p, DrawingCanvas c)
{
new FramedOval(p, SIZE, SIZE, c);
new Text(nextNum, p.getX()+SIZE/2, p.getY()+SIZE/2, c);
nextNum++;
}
}