Computer Science 252
Problem Solving with Java

Spring 2014, The College of Saint Rose

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
 * The College of Saint Rose, Fall 2013
 *
 * $Id: Snowman.java 2218 2013-10-18 14:06:39Z 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;
        }
    }
}