⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updateimage.java

📁 exploring Java 2ed edition 附带的例子程序
💻 JAVA
字号:
import java.awt.*;import java.awt.image.*;public class UpdateImage extends java.applet.Applet implements Runnable {	int arrayLength, pixels[];	MemoryImageSource source;	Image image;	int width, height;	public void init() {		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 void run() {		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);		}	}	public void paint( Graphics g ) {		g.drawImage(image, 0, 0, this);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -