/** * Skyline * @author Dave Musicant * @version 1/18/05 * * This class uses the Building2 class to generate a sample skyline. */ import java.awt.*; class Skyline { public static void main(String[] args) { // Create a canvas object and make it appear Canvas canvas = new Canvas("Skyline!"); int windowWidth = 500; int windowHeight = 500; canvas.setSize(windowWidth,windowHeight); canvas.setVisible(true); // Generate 50 building objects, and draw each one. // Sum up the area as you go along. int totalArea = 0; for (int i=0; i < 50; i++) { Building building = new Building(); building.setHeightRandom(windowHeight); building.setWidthRandom(windowWidth/5); building.setColorRandom(); building.setLocationRandom(windowWidth); building.draw(canvas,windowHeight); totalArea = totalArea + building.area(); } // Display results. System.out.println("Total area = " + totalArea); } }