import java.awt.*;
import java.awt.image.*;
public class ColorPan extends java.applet.Applet {
Image img;
int width, height;
int [] pixData;
public void init() {
width = getSize().width;
height = getSize().height;
pixData = new int [width * height];
int i=0;
for (int y = 0; y < height; y++) {
int red = (y * 255) / (height - 1);
for (int x = 0; x < width; x++) {
int green = (x * 255) / (width - 1);
int blue = 128;
int alpha = 255;
pixData[i++] = (alpha << 24) | (red << 16) | (green << 8 ) | blue;
}
}
}
public void paint( Graphics g ) {
if ( img == null )
img = createImage( new MemoryImageSource(width, height, pixData, 0, width));
g.drawImage( img, 0, 0, this );
}
}
|