Computer Science 202
Introduction to Programming

Fall 2013, The College of Saint Rose

GraphPaper Demo

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



GraphPaper BlueJ Project

Click here to download a BlueJ project for GraphPaper.


GraphPaper Source Code

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


GraphPaper.java


/**
 * Let's make some graph paper!  We'll use loops.
 * 
 * @author Jim Teresco
 * 
 * Developed in class, The College of Saint Rose
 * CSC 252, Fall 2013
 * 
 * $Id: GraphPaper.java 2223 2013-10-22 19:30:12Z terescoj $
 */

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

public class GraphPaper extends WindowController {

    private static final int SPACING = 10;
    
    public void begin() 
    {
        // first draw horizontal lines
        // set up for first iteration
        int nextY = SPACING;
        // keep going as long as we are not at the bottom of
        // the canvas.
        while (nextY < canvas.getHeight()) {
            // draw the next line
            new Line(0, nextY, canvas.getWidth(), nextY, canvas);
            // get ready to draw the next next line
            nextY = nextY + SPACING;
        }
        
        // do this again for vertical lines
        int nextX = SPACING;
        while (nextX < canvas.getWidth()) {
            new Line(nextX, 0, nextX, canvas.getHeight(), canvas);
            nextX = nextX + SPACING;
        }
    }

}