Computer Science 120
Introduction to Programming

Spring 2012, Siena College

RubberBand Demo

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



RubberBand BlueJ Project

Click here to download a BlueJ project for RubberBand.


RubberBand Source Code

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


RubberBand.java

import objectdraw.*;
import java.awt.*;

/*
 * Example RubberBand
 *
 * A simple program to draw a rubber band line.
 * This version creates a single line segment and
 * the changes the end point each time the mouse moves.
 *
 * Jim Teresco, Siena College, CSIS 120, Spring 2011
 * Original from Williams College, CSCI 134
 *
 * $Id: RubberBand.java 1501 2011-01-24 20:48:50Z terescoj $
 */

public class RubberBand extends WindowController {

    private Line line;          // the line being drawn
    
    public void onMousePress(Location pressedPoint) {
        line = new Line(pressedPoint, pressedPoint, canvas);
    }

    public void onMouseDrag(Location point) {
        line.setEnd(point);
    }
}