java 复制 双缓存_Java 双缓存

import java.awt.*;

import java.applet.*;

public class HelloWorld extends Applet

{

private Image imgBuf;

private Graphics gBuf;

Thread lithread=null;

private int i=0;

public void init()

{

imgBuf=createImage(getSize().width,getSize().height);

gBuf=imgBuf.getGraphics();

gBuf.setColor(Color.black);

gBuf.fillRect(0,0,getSize().width,getSize().height);

gBuf.setColor(Color.white);

gBuf.drawLine(0,10,getSize().width-1,10);

gBuf.drawLine(0,30,getSize().width-1,30);

gBuf.drawLine(0,50,getSize().width-1,50);

gBuf.drawLine(0,70,getSize().width-1,70);

gBuf.drawLine(0,90,getSize().width-1,90);

gBuf.drawLine(0,110,getSize().width-1,110);

gBuf.drawLine(0,130,getSize().width-1,130);

gBuf.setColor(Color.red);

gBuf.drawRect(0,0,getSize().width-1,getSize().height-1);

}

public void start()

{

if(lithread==null)

{

lithread=new Thread();

lithread.start();

}

}

public void stop()

{

lithread=null;

}

public void paint(Graphics g)

{

g.drawImage(imgBuf,0,0,this);

gBuf.setColor(Color.black);

gBuf.fillRect(0,0,getSize().width,getSize().height);

gBuf.setColor(Color.white);

gBuf.drawLine(0,10,getSize().width-1,10);

gBuf.drawLine(0,30,getSize().width-1,30);

gBuf.drawLine(0,50,getSize().width-1,50);

gBuf.drawLine(0,70,getSize().width-1,70);

gBuf.drawLine(0,90,getSize().width-1,90);

gBuf.drawLine(0,110,getSize().width-1,110);

gBuf.drawLine(0,130,getSize().width-1,130);

gBuf.setColor(Color.green);

gBuf.drawRect(50-i,50-i,200-i,100-i);

try

{

lithread.sleep(1000);

}

catch(InterruptedException e)

{

}

i++;

repaint();

}

public void update(Graphics g)

{

paint(g);

}

}

双缓存技术:

图像闪烁的根本原因是当一幅图像显示完需要花下一幅时,首先将屏幕用背景色清除,然后再画下一幅,因此人们能看到背景色因此出现闪烁.

当一幅图像在显示的时候,下一幅要显示的图像已经在内存中写好,因此,当需要下一幅时可以直接通过函数从内存中一次性独到显示区,由于从内存中读出速度很快,所以看不到闪烁.

http://www.matrix.org.cn/thread.shtml?topicId=15665&forumId=19

http://blog.chinaunix.net/u/18021/showart_1102572.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值