Computer Science 252
Problem Solving with Java

Fall 2013, 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.


MouseDroppings.java

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.
 *
 * Jim Teresco, Siena College, CSCI 120, Spring 2011
 * and The College of Saint Rose, CSC 202/252, Fall 2013
 *
 * $Id: MouseDroppings.java 2218 2013-10-18 14:06:39Z 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)
        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();
    }
}