Computer Science 252
Problem Solving with Java

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
 * Based on similar example from Williams College CS 134.
 * CSC 252, The College of Saint Rose, Fall 2013
 *
 * $Id: Scribble.java 2218 2013-10-18 14:06:39Z 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;
    }
}