废话少说了,下面是实现代码:
public class Shutter extends Canvas implements Runnable {
private Image img;
private boolean isStopped;
private int i;
Shutter() {
try {
img = Image.createImage("/ken.png");
}
catch (IOException e) {
}
// 开始描绘线程
new Thread(this).start();
}
/** 动画线程处理部分 */
public void run() {
i = 0;
while ( !isStopped) {
try {
repaint(); // 再描绘
Thread.sleep(100); // 等待一定时间
i += 5;
if ( i >= getWidth()) {
i = getWidth();
isStopped = true;
}
}
catch (InterruptedException e) {
}
}
}
protected void paint(Graphics g) {
g.setColor(0x00FFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
g.setClip(0, 0, 128, i);//从上到下显示
g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);
g.setClip(0, 0, i, 128);//从左到右显示
g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);
g.setClip(0,0,i,i);//从上到下从左到右显示
g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);
}
}
因为简单,就用图片显示了,如果是屏幕的话需要将屏幕绘制到图片上,如:
Image img = Image.createImage(width, height);
Grahpics g = img.getGraphics();
g.setColor(xxx);
g.drawImage(...);
...