import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class doublebuffer extends Applet implements Runnable
{
Image memoryimage;
Graphics memorygraphics;
Thread doublebufferthread;
boolean animateFlag = true;
int i;
//Initialize the applet
public void init()
{
memoryimage = createImage(100,100);
memorygraphics = memoryimage.getGraphics();
} public void start()
{
doublebufferthread = new Thread(this);
doublebufferthread.start();
} public void stop()
{
animateFlag = false;
} public void run()
{
try
{
while(true) {
Thread.sleep(200);
repaint();
}
}
catch(InterruptedException e)
{ }
} public void paint(Graphics g)
{
i += 5;
if(i>=100) i=5; memorygraphics.setColor(new Color(255,255,255));
memorygraphics.fillRect(0,0,100,100);
memorygraphics.setColor(new Color(0,0,0));
memorygraphics.drawRect(0,0,i,i);
g.drawImage(memoryimage,10,10,this);
}
}
import java.awt.event.*;
import java.applet.*;public class doublebuffer extends Applet implements Runnable
{
Image memoryimage;
Graphics memorygraphics;
Thread doublebufferthread;
boolean animateFlag = true;
int i;
//Initialize the applet
public void init()
{
memoryimage = createImage(100,100);
memorygraphics = memoryimage.getGraphics();
} public void start()
{
doublebufferthread = new Thread(this);
doublebufferthread.start();
} public void stop()
{
animateFlag = false;
} public void run()
{
try
{
while(true) {
Thread.sleep(200);
repaint();
}
}
catch(InterruptedException e)
{ }
} public void paint(Graphics g)
{
i += 5;
if(i>=100) i=5; memorygraphics.setColor(new Color(255,255,255));
memorygraphics.fillRect(0,0,100,100);
memorygraphics.setColor(new Color(0,0,0));
memorygraphics.drawRect(0,0,i,i);
g.drawImage(memoryimage,10,10,this);
}
}
解决方案 »
- 帮我看看那里写的不对啊?老是不能显示结果!
- 求助:SQL server中不支持ResultSet.last()怎么办啊?
- 调查:关于JAVA/J2EE设计模式的实际使用状况
- 为什么我的jsp页面会显示数据库中的null标志啊?
- 每次修改servlet都要重启tomcat吗?
- 求救!在工作中遇到关于timer的一个问题太头大了!
- 文件写操作的问题?为什么不能添加内容进已写入过内容的文件?
- 调用dll的问题???请高手指教!!!
- apache + ssl 问题,希望各位前辈帮助
- 知道为什么吗?
- 请问谁知道在VisualAge for java下出现No suitable driver是怎么回事
- 多谢 anubis 请接分
改成如下:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class doublebuffer extends Applet implements Runnable
{
Image memoryimage=null;
Graphics memorygraphics;
Thread doublebufferthread;
boolean animateFlag = true;
int i;
//Initialize the applet
public void init()
{
memoryimage=createImage(100,100);
memorygraphics = memoryimage.getGraphics();
} public void start()
{
doublebufferthread = new Thread(this);
doublebufferthread.start();
} public void stop()
{
animateFlag = false;
} public void run()
{
try
{
while(true) {
Thread.sleep(200);
repaint();
}
}
catch(InterruptedException e)
{ }
} public void paint(Graphics g)
{
i += 5;
if(i>=100) i=5;
if(memorygraphics==null)
memorygraphics = memoryimage.getGraphics();
memorygraphics.setColor(new Color(255,255,255));
memorygraphics.fillRect(0,0,100,100);
memorygraphics.setColor(new Color(0,0,0));
memorygraphics.drawRect(0,0,i,i);
g.drawImage(memoryimage,10,10,this);
}
}