// 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 p = new DrawingPanel(500, 400); p.setBackground(Color.CYAN); Graphics g = p.getGraphics(); draw(g, 50, 50, 100, 100); draw(g, 100, 200, 100, 100); draw(g, 250, 150, 75, 75); } // Draws a subfigure with upper-left of (x, y) and given width and height public static void draw(Graphics g, int x, int y, int width, int height) { g.setColor(Color.RED); g.fillRect(x, y, width, height); g.setColor(Color.GREEN); g.fillOval(x, y, width, height); g.setColor(Color.BLACK); g.drawRect(x, y, width, height); g.drawOval(x, y, width, height); g.drawLine(x, y, x + width, y + height); g.drawLine(x, y + height, x + width, y); } }