// CSE 142, Spring 2010, Marty Stepp // This program draws several "Building Java Programs" books // at various coordinates and sizes. // It demonstrates drawing with parameterized methods and loops. import java.awt.*; public class Book { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(520, 240); Graphics g = panel.getGraphics(); book(g, 20, 35, 100); book(g, 150, 70, 60); book(g, 300, 10, 200); } // Draws a book at the given x/y position and the given size. public static void book(Graphics g, int x, int y, int size) { // overall book outline g.setColor(Color.CYAN); g.fillRect(x, y, size, size); g.setColor(Color.WHITE); g.drawString("BJP", x + size/2, y + size/5); // bricks g.setColor(new Color(191, 118, 73)); for (int i = 0; i < 10; i++) { g.fillRect(x, y + size/10*i, size/10 + size/10*i, size/10 - 1); } } }