Graphics I Code Example                       Peter Komisar
 



import java.awt.*;

class Colors extends Frame{
public static void main(String[] args){
Label p=null;
Colors colors=new Colors( );
colors.setLayout(new GridLayout(3,4));
colors.setBackground(Color.white);
String[] colorArray= new String[]
{"  blue","  cyan","  darkGray","  gray","  green","  lightGray","  magenta",
 "  orange","  pink","  red","  white","  yellow"};

int[][] intArray=new int[][]{ new int[]{0,0,255},new int[]{0,255,255},
                              new int[]{64,64,64},new int[]{128,128,128},
                              new int[]{0,255,0},new int[]{192,192,192},
                              new int[]{255,0,255},new int[]{255,160,0},
                              new int[]{255,170,170}, new int[]{255,0,0},
                              new int[]{255,255,255},new int[]{255,255,0}
                            };

for(int i=0;i<12;i++){
   p =new Label(colorArray[i]);
   p.setBackground(new Color(intArray[i][0],intArray[i][1],intArray[i][2]));
   if(colorArray[i].equals("  darkGray"))
   p.setForeground(Color.white);
   colors.add(p);
   }

colors.setSize(400,400);
colors.setVisible(true);
GetColors gc=new GetColors();

  }
 }

/* A class just to get the red green blue values of the base set of colors. */
 

class GetColors{
GetColors(){
int r,g,b;
 

r=Color.blue.getRed();
g=Color.blue.getGreen();
b=Color.blue.getBlue();
System.out.println("blue: "+r +" "+ g +" "+ b);
 

r=Color.cyan.getRed();
g=Color.cyan.getGreen();
b=Color.cyan.getBlue();
System.out.println("cyan: "+r +" "+ g +" "+ b);
 

r=Color.darkGray.getRed();
g=Color.darkGray.getGreen();
b=Color.darkGray.getBlue();
System.out.println("darkGray: "+r +" "+ g +" "+ b);
 

r=Color.gray.getRed();
g=Color.gray.getGreen();
b=Color.gray.getBlue();
System.out.println("gray: "+r +" "+ g +" "+ b);
 

r=Color.green.getRed();
g=Color.green.getGreen();
b=Color.green.getBlue();
System.out.println("green: "+r +" "+ g +" "+ b);

r=Color.lightGray.getRed();
g=Color.lightGray.getGreen();
b=Color.lightGray.getBlue();
System.out.println("lightGray: "+r +" "+ g +" "+ b);

r=Color.magenta.getRed();
g=Color.magenta.getGreen();
b=Color.magenta.getBlue();
System.out.println("magenta: "+r +" "+ g +" "+ b);

r=Color.orange.getRed();
g=Color.orange.getGreen();
b=Color.orange.getBlue();
System.out.println("orange: "+r +" "+ g +" "+ b);

r=Color.pink.getRed();
g=Color.pink.getGreen();
b=Color.pink.getBlue();
System.out.println("pink: "+ r +" "+ g +" "+ b);

r=Color.red.getRed();
g=Color.red.getGreen();
b=Color.red.getBlue();
System.out.println("red: "+ r +" "+ g +" "+ b);

r=Color.white.getRed();
g=Color.white.getGreen();
b=Color.white.getBlue();
System.out.println("white: "+ r +" "+ g +" "+ b);

r=Color.yellow.getRed();
g=Color.yellow.getGreen();
b=Color.yellow.getBlue();
System.out.println("yellow: "+ r +" "+ g +" "+ b);
 }
}