ColorTest.java


This is the syntax highlighted version of ColorTest.java from 3.1 Using Data Types of
Introduction to Computer Science by Robert Sedgewick and Kevin Wayne.


/*************************************************************************
 *  Compilation:  javac ColorTest.java
 *  Execution:    java ColorTest
 *
 *************************************************************************/

import java.awt.Color;

public class ColorTest { 

    public static void main(String[] args) { 
        Color magenta = new Color(255, 0, 255);
        int r = magenta.getRed();
        int g = magenta.getGreen();
        int b = magenta.getBlue();
        System.out.println("r = " + r + ", g = " + g + ", b = " + b);
        System.out.println("magenta = " + magenta);
        Color c = magenta.darker();
        System.out.println("dark magenta = " + c);

        Color blue1 = new Color(0, 0, 255);
        Color blue2 = new Color(0, 0, 255);
        if (blue1 != blue2)      System.out.println("reference are not equal");
        if (blue1.equals(blue2)) System.out.println("objects hold same values");
    }

}


Last updated: Fri Jul 16 15:45:57 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.