Trung
Posts: 9
Nickname: chitrung
Registered: Jun, 2002
|
|
Re: animation
|
Posted: Jun 27, 2002 8:59 AM
|
|
hi, may be this help you out. the code isn't exactly the same like yours but it do the same like yours.
import java.applet.*; import java.awt.*;
public class ShapeTest extends Applet implements Runnable { Image offimg; Graphics offscreen; Thread thread; int x = 0, y = 0; public void init() { offimg = createImage(size().width, size().height); offscreen = offimg.getGraphics(); } public void start() { thread = new Thread(this); thread.start(); } public void stop() { thread = null; } public void run() { Thread thisThread = Thread.currentThread(); while (thread == thisThread) { x++; y++; repaint(); try{ Thread.sleep(50); }catch(Exception ex) {} } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { offscreen.setColor(Color.white); offscreen.fillRect(0,0, size().width, size().height); offscreen.setColor(Color.red); offscreen.fillRect(x,y,20,20); g.drawImage(offimg, 0, 0, this); }
}
|
|