1 /* 2 * File: MyColorBoxes.java 3 * 4 * Display pre-defined colors 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.applet.Applet; 11 import java.awt.Graphics; 12 import java.awt.Color; 13 14 public class MyColorBoxes extends Applet { 15 16 // Define three colors: 17 private Color brown = new Color( 0xA5, 0x2A, 0x2A ); 18 private Color turquoise = new Color( 0x40, 0xE0, 0xD0 ); 19 private Color violet = new Color( 0xEE, 0x82, 0xEE ); 20 21 public void paint( Graphics g ) { 22 23 // Draw the first row of color boxes: 24 g.setColor( Color.black ); 25 g.fillRect( 10, 10, 50, 50 ); 26 g.setColor( Color.blue ); 27 g.fillRect( 80, 10, 50, 50 ); 28 g.setColor( Color.cyan ); 29 g.fillRect( 150, 10, 50, 50 ); 30 g.setColor( Color.darkGray ); 31 g.fillRect( 220, 10, 50, 50 ); 32 33 // Draw the second row of color boxes: 34 g.setColor( Color.gray ); 35 g.fillRect( 10, 80, 50, 50 ); 36 g.setColor( Color.green ); 37 g.fillRect( 80, 80, 50, 50 ); 38 g.setColor( Color.lightGray ); 39 g.fillRect( 150, 80, 50, 50 ); 40 g.setColor( Color.magenta ); 41 g.fillRect( 220, 80, 50, 50 ); 42 43 // Draw the third row of color boxes: 44 g.setColor( Color.orange ); 45 g.fillRect( 10, 150, 50, 50 ); 46 g.setColor( Color.pink ); 47 g.fillRect( 80, 150, 50, 50 ); 48 g.setColor( Color.red ); 49 g.fillRect( 150, 150, 50, 50 ); 50 g.setColor( Color.white ); 51 g.fillRect( 220, 150, 50, 50 ); 52 53 // Draw the fourth row of color boxes: 54 g.setColor( Color.yellow ); 55 g.fillRect( 10, 220, 50, 50 ); 56 g.setColor( brown ); 57 g.fillRect( 80, 220, 50, 50 ); 58 g.setColor( turquoise ); 59 g.fillRect( 150, 220, 50, 50 ); 60 g.setColor( violet ); 61 g.fillRect( 220, 220, 50, 50 ); 62 63 } 64 65 }