Computer Science 120
Introduction to Programming

Spring 2011, Siena College

Snowman Demo

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



Snowman BlueJ Project

Click here to download a BlueJ project for Snowman.


Snowman Source Code

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


Snowman.java

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

/*
 * Example Snowman: a VisibleImage example
 *
 * Jim Teresco, Siena College, CSIS 120, Spring 2011
 *
 * $Id: template.java 1501 2011-01-24 20:48:50Z terescoj $
 */

public class Snowman extends WindowController {

    // an objectdraw object that can store a picture
    private VisibleImage snowMan;

    // for dragging
    private Location lastPoint;

    public void begin() {
        // load our image
        Image snowManPic = getImage("snowman.gif");

        // create an objectdraw object using that image
        snowMan = new VisibleImage(snowManPic, 10, 10, canvas);

        snowMan.setWidth(124);
        snowMan.setHeight(144);
    }

    public void onMousePress(Location point) {
        lastPoint = point;
    }

    public void onMouseDrag(Location point) {
        
        if ( snowMan.contains( lastPoint ) ) {
            snowMan.move(point.getX()-lastPoint.getX(),
                point.getY()-lastPoint.getY());
            lastPoint = point;
        }
    }
}