import java.awt.*; public class Size { public static void main(String[] args) { DrawingPanel p = new DrawingPanel(200, 200); Graphics g = p.getGraphics(); // This is a forever loop // If you do this in your animations you won't be able // to save them as an image for(;;) { // Animate squares getting bigger for (int i = 0; i < 50; i++) { drawSquare(p, g, i * 4); } // Animate squares getting smaller for (int i = 50; i > 0; i--) { drawSquare(p, g, i * 4); } } } // Erases the canvas // Draws a square at 0, 0 that is size 'size' // Sleeps the panel for 1/20 of a second public static void drawSquare(DrawingPanel p, Graphics g, int size) { g.setColor(Color.WHITE); g.fillRect(0, 0, 200, 200); g.setColor(Color.RED); g.drawRect(0, 0, size, size); p.sleep(50); } }