import java.awt.*; import java.awt.image.*; public class Graphics5 { public static final int RED = 0xFF0000; public static final int GREEN = 0x00FF00; public static final int BLUE = 0x0000FF; public static final int YELLOW = 0xFFFF00; public static final int BLACK = 0x000000; static public void pause(int n) throws Exception { Thread.sleep( 100 * n ); } static public void main(String[] args) throws Exception { /* ------------------------------------------------ Preparing to draw picture... ------------------------------------------------ */ Canvas pic = new MyCanvas(); // Make a canvas (2 dim array) Frame f = new Frame( "My image" ); // Create a window f.add("Center", pic); // Put the canvas in the window f.setSize(MyCanvas.MAX_X, MyCanvas.MAX_Y); // Set size of the window f.setVisible(true); // Make window visible /* ------------------------------------------------ Draw a 10x10 box at (100,100) ------------------------------------------------ */ for (int i = 0; i < 10; i++ ) for (int j = 0; j < 10; j++ ) MyCanvas.Image.setRGB(100+i, 100+j, YELLOW); pic.repaint(); // Repaint the picture pause(20); /* ------------------------------------------------ ERASE the 10x10 box at (100,100) ------------------------------------------------ */ for (int i = 0; i < 10; i++ ) for (int j = 0; j < 10; j++ ) MyCanvas.Image.setRGB(100+i, 100+j, BLACK); pic.repaint(); // Repaint the picture /* ------------------------------------------------ Draw the same 10x10 box at (200,100) ------------------------------------------------ */ for (int i = 0; i < 10; i++ ) for (int j = 0; j < 10; j++ ) MyCanvas.Image.setRGB(200+i, 100+j, YELLOW); pic.repaint(); // Repaint the picture pause(50); } }