FileDocCategorySizeDatePackage
UpdateImage.javaAPI DocExample1060Tue Dec 02 02:59:40 GMT 1997None

UpdateImage

public class UpdateImage extends Applet implements Runnable

Fields Summary
int
arrayLength
int[]
pixels
MemoryImageSource
source
Image
image
int
width
int
height
Constructors Summary
Methods Summary
public voidinit()

		width = getSize().width; height = getSize().height;
		arrayLength = width * height;
		pixels = new int [arrayLength];

		source = new MemoryImageSource(width, height, pixels, 0, width);
		source.setAnimated(true);
		image = createImage(source);
		// bad form... start threads in start(), stop them in stop()
		new Thread(this).start();
	
public voidpaint(java.awt.Graphics g)

		g.drawImage(image, 0, 0, this);
	
public voidrun()

		while (true) {
			try {
				Thread.sleep(1000/24);
			} catch( InterruptedException e ) { /* die */ }

			for (int x = 0; x < width; x++) 
				for (int y = 0; y < height; y++)  {
					boolean rand = Math.random() > 0.5;
					pixels[y*width+x] = 
						rand ? Color.black.getRGB() : Color.white.getRGB();
				}

			// Push out the new data
			source.newPixels(0, 0, width, height);
		}