// This is a simple drawing program that draws three versions of a particular // subfigure on the screen. This version is structured so that main calls // three methods to draw the subfigures. import java.awt.*; public class Draw2 { public static void main(String[] args) { DrawingPanel p = new DrawingPanel(500, 400); p.setBackground(Color.CYAN); Graphics g = p.getGraphics(); draw1(g); draw2(g); draw3(g); } // Draws a subfigure with upper-left of (50, 50) and lower-right of // (150, 150) public static void draw1(Graphics g) { g.setColor(Color.RED); g.fillRect(50, 50, 100, 100); g.setColor(Color.GREEN); g.fillOval(50, 50, 100, 100); g.setColor(Color.BLACK); g.drawRect(50, 50, 100, 100); g.drawOval(50, 50, 100, 100); g.drawLine(50, 50, 150, 150); g.drawLine(50, 150, 150, 50); } // Draws a subfigure with upper-left of (100, 200) and lower-right of // (200, 300) public static void draw2(Graphics g) { g.setColor(Color.RED); g.fillRect(100, 200, 100, 100); g.setColor(Color.GREEN); g.fillOval(100, 200, 100, 100); g.setColor(Color.BLACK); g.drawRect(100, 200, 100, 100); g.drawOval(100, 200, 100, 100); g.drawLine(100, 200, 200, 300); g.drawLine(100, 300, 200, 200); } // Draws a subfigure with upper-left of (250, 150) and lower-right of // (325, 225) public static void draw3(Graphics g) { g.setColor(Color.RED); g.fillRect(250, 150, 75, 75); g.setColor(Color.GREEN); g.fillOval(250, 150, 75, 75); g.setColor(Color.BLACK); g.drawRect(250, 150, 75, 75); g.drawOval(250, 150, 75, 75); g.drawLine(250, 150, 325, 225); g.drawLine(250, 225, 325, 150); } }