import! java.awt.*;
import! java.applet!.*;
public class testDubleBuffer extends Applet! implements Runnable
{
int x, y;
boolean posX, posY;
Image offImg;
Graphics gc;
Thread thr;
public void init(){
this.x = 0;
this.y = 0;
this.posX = true;
this.posY = true;
}
public void start()
{
offImg = this.createImage(this.getWidth(), this.getHeight());
gc = this.offImg.getGraphics();
this.thr = new Thread(this);
this.thr.start();
}
public void destroy(){}
public void stop(){}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(this.offImg, 0, 0, this);
}
public void paintComp(Graphics g){
g.setColor(Color.GREEN);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.WHITE);
g.fillOval(x, y, 30, 30);
}
public void run()
{
while(true)
{
this.paintComp(this.gc);
try
{
if(this.posX)
this.x+=3;
else
this.x-=3;
if(this.posY)
this.y+=3;
else
this.y-=3;
if(x + 30 > this.getWidth()) this.posX = false;
if(y + 30 > this.getHeight()) this.posY = false;
if(x < 0) this.posX = true;
if(y < 0) this.posY = true;
Thread.sleep(25);
}catch(Exception e){}
this.repaint();
}
}
}
'IT_Programming > Java' 카테고리의 다른 글
JAVA로 stored Procedure 호출하기 (with mssql 2000) (0) | 2008.05.14 |
---|---|
[펌] JDOM을 이용한 URL XML 파싱~ 간단한 예제 (0) | 2008.04.05 |
JTable에 클립보드를 이용해서 붙이고 카피하기. (0) | 2008.03.29 |
Thread로 구현한 HTML 다운로더 (0) | 2008.03.14 |
Copy and Paste using Swing (0) | 2008.01.28 |