MovingRectangles


Your browser is ignoring the <APPLET> tag!

The interesting part of this program (if there is any!) is the text output, rather than the rectangles drawn. The point is to understand which variables see a change when an object changes. Read the code, look at what each section does and look at the text output.

In Safari and Firefox, the text output comes out in the "Java Console" window. Internet Explorer probably has a similar window.

import objectdraw.*;

public class MovingRectangles extends WindowController
{
    public void begin() {
        FilledRect rect = new FilledRect (10, 20, 30, 40, canvas);
        FilledRect rect2 = rect;
        rect2.move (0, 10);
        System.out.println ("rect's top = " + rect.getY());
        System.out.println ("rect2's top = " + rect2.getY());
        
        rect2 = new FilledRect (0, 0, 100, 100, canvas);
        System.out.println ("rect's top = " + rect.getY());
        System.out.println ("rect2's top = " + rect2.getY());
         
        int x = 0;
        int y = x;
        x++;
        System.out.println ("x = " + x);
        System.out.println ("y = " + y);
    }
}