// This is a simple drawing program that draws three versions of a particular // subfigure on the screen. This version has a generalized method for // drawing the subfigures that is called three different times. import java.awt.*; public class Draw3 { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(500, 400); panel.setBackground(Color.CYAN); Graphics g = panel.getGraphics(); draw(g, 50, 50, 100); draw(g, 100, 200, 100); draw(g, 250, 150, 75); } // Draws a subfigure with upper-left of (x, y) and given size using // the provided Graphics object public static void draw(Graphics g, int x, int y, int size) { g.setColor(Color.RED); g.fillRect(x, y, size, size); g.setColor(Color.GREEN); g.fillOval(x, y, size, size); g.setColor(Color.BLACK); g.drawRect(x, y, size, size); g.drawOval(x, y, size, size); g.drawLine(x, y, x + size, y + size); g.drawLine(x, y + size, x + size, y); } }