// Helene Martin, CSE 142 // Draws a scalable table at different locations. // goal: re-iterate that to generalize drawing methods, follow these steps: // 1) add x and y parameters // 2) replace specific position numbers in definition with expressions using x and y // 3) add size parameter // 4) replace specific size numbers in definition with expressions using size import java.awt.*; public class DrawTable { public static void main(String[] args) { DrawingPanel p = new DrawingPanel(400, 400); Graphics g = p.getGraphics(); drawTable(g, 40, 40, 100); drawTable(g, 140, 200, 120); //drawTable2(g); //drawTable3(g); } // Draws a table of width size at position x, y // // Note that the final width of the table is actually size + size / 20 because // of the thickness of the right table leg. You could choose to draw the second // table leg at x position (x + size - size / 20) instead of at (x + size) if you // wanted the true total width to be size. public static void drawTable(Graphics g, int x, int y, int size) { g.fillRect(x, y, size, size / 10); g.fillRect(x, y, size / 20, size * 2 / 5); g.fillRect(x + size, y, size / 20, size * 2 / 5); } // Draws a table of width 100 at position 140, 200 public static void drawTable2(Graphics g) { g.fillRect(140, 200, 100, 10); g.fillRect(140, 200, 5, 40); g.fillRect(240, 200, 5, 40); } // Draws a table of width 120 at position 140, 200 public static void drawTable3(Graphics g) { g.fillRect(140, 200, 120, 12); g.fillRect(140, 200, 6, 48); g.fillRect(260, 200, 6, 48); } }