An applet to explore Color XOR mode with standard named colors
This also illustrates use of Applet PARAMeters
This applet shows the colors that result when standard colors are
combined with XOR.
The first rectangle in each row and column is a standard named color
in java's Color class.
Each remaining rectangle is the XOR of the color
on the right of the row and the color on the top of the column.
And this is the java code of the applet
import java.awt.*;
import java.util.*;
import java.applet.Applet;
public class XOR extends Applet {
// data stating parameters for drawing the clock
private int windowWidth;
private int windowHeight;
private int numColors;
private int frameDelay = 100; // roughly a 40th of a second
public void paint( Graphics page ) {
windowWidth = Integer.parseInt(getParameter("width"));
windowHeight = Integer.parseInt(getParameter("height"));
numColors = Integer.parseInt(getParameter("numColors"));
System.out.println(windowWidth);
System.out.println(windowHeight);
System.out.println(numColors);
setBackground( Color.white );
// The 13 colors with defined names
Color color[] =
{Color.black, Color.blue, Color.cyan, Color.darkGray,
Color.gray, Color.green, Color.lightGray, Color.magenta,
Color.orange, Color.pink, Color.red, Color.yellow,
Color.white};
String colorName[] =
{"black", "blue", "cyan", "darkGray",
"gray", "green", "lightGray", "magenta",
"orange", "pink", "red", "yellow",
"white"};
int numStripes = numColors + 1;
int bandWidth = windowWidth/numStripes ;
int bandHeight = windowHeight/numStripes ;
// paint vertical stripes (leave first stripe alone)
for ( int i = 1; i <= numColors; i++ ) {
page.setColor( color[i-1] );
// the vertical stripes
page.fillRect( i*bandWidth, 0,
bandWidth, windowHeight);
// row header blocks
page.fillRect( 0, i*bandHeight,
bandWidth, bandHeight);
page.setColor ( Color.white );
page.drawString( colorName[i-1], 0, i*bandHeight );
}
// paint horizontal stripes (leave first stripe alone)
// XORing with vertical stripes.
if ( getParameter( "horizontal" ).equals( "true" ) )
for ( int i = 1; i <= numColors; i++ ) {
page.setXORMode( color[i-1] );
page.fillRect( bandWidth, i*bandHeight,
windowWidth - bandWidth, bandHeight );
}
} // method paint
} // class XOR