FileDocCategorySizeDatePackage
SystemColorList.javaAPI DocExample2438Mon Sep 22 13:30:30 BST 1997None

SystemColorList

public class SystemColorList extends Applet
An applet that displays all of the predefined system colors.

Fields Summary
String[]
color_names
SystemColor[]
colors
Constructors Summary
Methods Summary
public voidinit()


     
    // Use a bunch of Label objects arranged in a grid to display the colors.
    this.setLayout(new GridLayout(0, 3, 5, 5));
    for(int i = 0; i < colors.length; i++) {
      // Create a label object to display a system color and its name
      Label l = new Label(color_names[i], Label.CENTER);
      this.add(l);
      // compute a foreground color to contrast with the background
      Color bg  = colors[i], fg;
      int r = bg.getRed(), g = bg.getGreen(), b = bg.getBlue();
      int avg = (r + g + b) / 3;
      if (avg > 128) fg = Color.black;
      else fg = Color.white;
      // And assign the colors.
      l.setBackground(bg);
      l.setForeground(fg);
    }