1 /* 2 * File: ColorBox1.java 3 * 4 * Drawing random color boxes 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 */ 8 9 import java.awt.Color; 10 import java.awt.Graphics; 11 12 public class ColorBox1 extends java.applet.Applet { 13 14 int i, j; 15 int m, n; 16 17 int ColorArray_R[][] = new int[12][12]; 18 int ColorArray_G[][] = new int[12][12]; 19 int ColorArray_B[][] = new int[12][12]; 20 21 public void init() { 22 for (int i=0; i<12; i++) { 23 for (int j=0; j<12; j++) { 24 ColorArray_R[i][j] = (int)Math.floor(Math.random()*256); 25 ColorArray_G[i][j] = (int)Math.floor(Math.random()*256); 26 ColorArray_B[i][j] = (int)Math.floor(Math.random()*256); 27 } 28 } 29 } 30 31 32 public void paint(Graphics g) { 33 i=0; j=0; 34 for (i=0; i<12; i++) { 35 for (j=0; j<12; j++) { 36 g.setColor(new Color(ColorArray_R[i][j], ColorArray_G[i][j], ColorArray_B[i][j])); 37 g.fillRect(10+i*30, 10+j*30, 25, 25); 38 g.setColor(Color.black); 39 g.drawRect(10+i*30, 10+j*30, 25, 25); 40 } 41 } 42 } 43 }