当前位置: 技术问答>java相关
我做了一个几张图叠加的java applet,闪烁的非常厉害,我该怎么办!
来源: 互联网 发布时间:2014-12-30
本文导语: | 用double buffer技术 import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Test extends Canvas { private Image[] backing = new Image[2]; private int imageToDraw = 1; private int imageNotDraw = 0; public void update(Graphics...
|
用double buffer技术
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends Canvas
{
private Image[] backing = new Image[2];
private int imageToDraw = 1;
private int imageNotDraw = 0;
public void update(Graphics g)
{
paint(g);
}
public synchronized void paint(Graphics g)
{
g.drawImage(backing[imageToDraw],0,0,this);
}
public void addNotify()
{
super.addNotify();
backing[0]=createImage(400,400);
backing[1] = createImage(400, 400);
setSize(400,400);
new Thread(new Runnable()
{
private int direction = 1;
private int position =0;
public void run()
{
for(;;)
{
try
{
Thread.sleep(10);
}
catch(InterruptedException e)
{e.printStackTrace();}
Graphics g = backing[imageNotDraw].getGraphics();
// g.clearRect(0,0,400,400);
g.setColor(Color.pink);
g.fillRect(0,0,400,400);
g.setColor(Color.black);
g.drawOval(position,200-position,400-(2*position),72*position);
synchronized(Test.this)
{
int temp = imageNotDraw;
imageNotDraw =imageToDraw;
imageToDraw = temp;
}
position +=direction;
if(position>199)
direction=-1;
else
if(position
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends Canvas
{
private Image[] backing = new Image[2];
private int imageToDraw = 1;
private int imageNotDraw = 0;
public void update(Graphics g)
{
paint(g);
}
public synchronized void paint(Graphics g)
{
g.drawImage(backing[imageToDraw],0,0,this);
}
public void addNotify()
{
super.addNotify();
backing[0]=createImage(400,400);
backing[1] = createImage(400, 400);
setSize(400,400);
new Thread(new Runnable()
{
private int direction = 1;
private int position =0;
public void run()
{
for(;;)
{
try
{
Thread.sleep(10);
}
catch(InterruptedException e)
{e.printStackTrace();}
Graphics g = backing[imageNotDraw].getGraphics();
// g.clearRect(0,0,400,400);
g.setColor(Color.pink);
g.fillRect(0,0,400,400);
g.setColor(Color.black);
g.drawOval(position,200-position,400-(2*position),72*position);
synchronized(Test.this)
{
int temp = imageNotDraw;
imageNotDraw =imageToDraw;
imageToDraw = temp;
}
position +=direction;
if(position>199)
direction=-1;
else
if(position
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!