// This program draws two rectangles filled with diagonal lines. import java.awt.*; public class Lines { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(500, 500); Graphics g = panel.getGraphics(); drawLineFigure(g, 10, 10, 10); drawLineFigure(g, 220, 30, 40); } // Draws one rectangle at the given x/y position // filled with the given number of diagonal lines. public static void drawLineFigure(Graphics g, int x, int y, int lines) { g.drawRect(x, y, 200, 200); for (int i = 0; i < 10; i++) { // lines on the upper-left half g.drawLine(x, y + 20 * i, x + 20 * i, y); // lines on the lower-right half g.drawLine(x + 20 * i, 200 + y, 200 + x, y + 20 * i); } } }