import java.awt.*; import java.awt.image.*; public class Draw4 { static public void pause(int n) throws Exception { Thread.sleep( 100 * n ); // pause for 100*n msec } /* =========================================================== The "move_right" method copies the "image" stored in the variable "pixel" one column to the right col-1 col . --> . . --> . . --> . =========================================================== */ public static void move_right(int[][] pixel) { for ( int col = 400-1; col >= 1; col-- ) for ( int row = 0; row < 300; row++ ) pixel[col][row] = pixel[col-1][row]; /* --------------------------------------------- Fill the left most column with BLACK pixels --------------------------------------------- */ for ( int row = 0; row < 300; row++ ) pixel[row][0] = 0; // 0 = BLACK } static public void main(String[] args) throws Exception { final int YELLOW = 0xFFFF00; // = 16711680+65280 (Red + Green) final int RED = 0xFF0000; // = 16711680 final int GREEN = 0x00FF00; // = 65280 final int BLUE = 0x0000FF; // = 255 final int BLACK = 0x000000; // = 0 /* ------------------------------------------------ Preparing to draw picture... ------------------------------------------------ */ MyCanvas 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(400,300); // Set size of the window f.setVisible(true); // Make window visible int[][] a = new int[400][300]; // This array hold the picture int row, col; for (col = 0; col < 400; col++ ) for (row = 0; row < 300; row++ ) a[col][row] = BLACK; for (col = 100; col < 110; col++ ) for (row = 200; row < 210; row++ ) a[col][row] = YELLOW; for ( int k = 0; k < 220; k++ ) { pic.draw(a); // Draw the picture in a[][] pause(1); move_right(a); } System.exit(0); } }