// CSE 142, Autumn 2010 // Author: Marty Stepp // This program draws several textbook figures at different positions. // It is a demonstration of graphics with for loops and methods with parameters. import java.awt.*; public class Book { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(600, 600); Graphics g = panel.getGraphics(); book(g, 20, 35, 100); book(g, 200, 105, 200); } // Draws a textbook figure at the given x/y position, scaled // to the given size. public static void book(Graphics g, int x, int y, int size) { g.setColor(Color.CYAN); g.fillRect(x, y, size, size); g.setColor(Color.RED); for (int i = 0; i < 10; i++) { g.fillRect(x, y + (size/10)*i, 10 + (size/10)*i, (size/10)-1); } //g.fillRect(20, 35, 10, 9); //g.fillRect(20, 45, 20, 9); //g.fillRect(20, 55, 30, 9); } }