Animating a line
2 posts in topic
Flat View  Flat View

Posted By:   Garrett_Allen
Posted On:   Thursday, July 24, 2003 09:49 AM

I can draw a line on a canvas, and then run a for loop to make it move, but it draws every frame on the canvas at once, instead of each frame at a time.

How do I make it display each frame, in order to animate the moving line?

Re: Animating a line

Posted By:   Anonymous  
Posted On:   Thursday, September 18, 2003 12:44 AM

This a java , you have to learn to use Threads, if you wantto write multithread programs.

check the code below, use your imagination, and u'll get the result.

public class Animator extends Frame implements Runnable{

int x=0;
int y=0;
public Animator(){
public void run(){
}catch(Exception ignore){}
public void paint(Graphics g){
public static void main(String [] args){
Animator a=new Animator();
Thread t=new Thread(a);;

Re: Animating a line

Posted By:   Stephen_McConnell  
Posted On:   Friday, July 25, 2003 05:29 AM

You have to put some wait state in-between each draw.

Usually, you create a thread that redraws the canvas. Then, you put it to sleep for a few milli seconds between each draw.

This way, you can go on with executing something else in your program while the thread takes care of the animation. Just running a loop to redraw it does so faster than one wants (unless you are programming on the Apple II then it took forever... even in 6502 Assembler Language).

Stephen McConnell

About | Sitemap | Contact