Computer Science 120
Introduction to Programming
Spring 2011, Siena College
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.
*
* Jim Teresco, Siena College, CSCI 120, Spring 2011
*
* $Id: MouseDroppings.java 1496 2011-01-20 20:01:52Z 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();
}
}