Computer Science 252
Problem Solving with Java

Spring 2014, The College of Saint Rose

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
 * The College of Saint Rose, Fall 2013
 * Original from Williams College, CSCI 134
 *
 * $Id: RubberBand.java 2218 2013-10-18 14:06:39Z 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);
    }
}