/* TestGObject.java * * Bruce M. Bolden * February 8, 1998 * http://www.cs.uidaho.edu/~bruceb/ */ import java.io.*; import java.awt.*; public class TestGObject extends CloseableFrame { /* Must declare objects as static Error : Can''t make a static reference to nonstatic variable circle in class TestGObject. TestGObject.java line 31 circle.showArea(); */ static Circle circle = new Circle(); static Circle circle2 = new Circle( 50, 50, Color.red ); static Square square = new Square( 50, 50, Color.green ); static Square square2 = new Square( 150, 150, Color.blue, 35 ); static Rectangle rect = new Rectangle( 100, 100, Color.green, 10, 20 ); static Rectangle rect2 = new Rectangle( 200, 200, Color.blue, 25, 75 ); public static void main( String[] args ) { TestGObject f = new TestGObject(); f.resize( 400, 400 ); f.show(); // Show the "properties" of the objects /* Must use the object to access our function Error : Can''t make static reference to method void showObjectProperties() in class TestGObject. TestGObject.java line 33 showObjectProperties(); */ f.showObjectProperties(); } /** Draw the objects */ public void paint( Graphics g ) { circle.draw( g ); circle2.draw( g ); square.draw( g ); square2.draw( g ); rect2.draw( g ); } /** Show the "properties" of the objects */ private void showObjectProperties() { System.out.print( "Area of circle: " ); TestGObject.circle.showArea(); System.out.print( "Area of circle2: " ); circle2.showArea(); System.out.print( "Area of square: " ); square.showArea(); System.out.print( "Area of square2: " ); square2.showArea(); System.out.print( "Area of rect: " ); rect.showArea(); System.out.print( "Area of rect2 : " ); rect2.showArea(); System.out.print( "Color of circle: " ); circle.showColor(); System.out.print( "Color of circle2: " ); circle2.showColor(); System.out.print( "Color of square: " ); square.showColor(); System.out.print( "Color of square2: " ); square2.showColor(); System.out.print( "Color of rect: " ); rect.showColor(); System.out.print( "Color of rect2: " ); rect2.showColor(); // change color rect2.setColor( Color.white ); System.out.print( "Color of rect2: " ); rect2.showColor(); } }