Computer Science 202
Introduction to Programming

Fall 2013, The College of Saint Rose

Scribble Demo

A working demo of Scribble will appear below. Click inside the applet to interact with it.



Scribble BlueJ Project

Click here to download a BlueJ project for Scribble.


Scribble Source Code

The Java source code for Scribble is below. Click on a file name to download it.


Scribble.java

import objectdraw.*;

/*
 * This program is a "scribbler".  When the mouse is pressed then dragged,
 * a series of lines are drawn from the previous point to the current location.
 *
 * Jim Teresco, Siena College, CSCI 120, Spring 2011
 * The College of Saint Rose, Fall 2013
 * Based on similar example from Williams College CS 134.
 *
 * $Id: Scribble.java 1496 2011-01-20 20:01:52Z terescoj $
 */
public class Scribble extends WindowController {

    // Last coordinate, to be used to draw next line segment
    private Location prevPoint;

    /*
     * When the mouse is pressed, save the press point to be used as
     * the first endpoint of the first line drawn during dragging
     */
    public void onMousePress(Location point) {
        prevPoint = point;
    } 

    /*
     * As the user is dragging, draw a line from the last saved point to
     * current point, and update last saved point.
     */
    public void onMouseDrag(Location point) {

        new Line(prevPoint, point, canvas);
        prevPoint = point;
    }
}