Computer Science 252
 Problem Solving with Java
Fall 2015, The College of Saint Rose
MouseDroppings Demo
A working demo of MouseDroppings will appear below. Click inside the applet to interact with it.
MouseDroppings BlueJ Project
Click here to download a BlueJ project for MouseDroppings.
MouseDroppings Source Code
The Java source code for MouseDroppings is below. Click on a file name to download it.
import objectdraw.*;
import java.awt.*;
/*
 * This program causes the mouse to "drop" a red sphere on the canvas each
 * time it is moved.  This demonstrates the use of the "point" parameter
 * for our mouse event handlers.  It also gives an idea of how quickly our
 * mouse move events are delivered to the program.
 *
 * Jim Teresco, Siena College, CSCI 120, Spring 2011
 * and The College of Saint Rose, CSC 202/252, Fall 2013, Spring 2015
 *
 * $Id: MouseDroppings.java 2523 2015-01-16 21:36:54Z terescoj $
 */
public class MouseDroppings extends WindowController {
    /* drop a small red oval at the point where the mouse just moved */
    public void onMouseMove(Location point) {
        // note that we can attach the setColor to the end
        // of our construction (but only if we are not remembering
        // a name for the object created -- if we are doing that
        // Java would use the return value of the last method call
        // as the return type, which in this case is "void".
        new FilledOval(point, 10, 10, canvas).setColor(Color.red);
    }
    /* clear the canvas if the mouse leaves the window */
    public void onMouseExit(Location point) {
        canvas.clear();
    }
}