If you write the animation with a loop that keeps drawing new images of graphics objects, you cause a problem for the browser by having a long computation. (The browser will either freeze the window or eventually crash.) |
This can be fixed by creating a Thread and putting the continual loop into a method called run that is the computation of the Thread. The run method is then executed independently of the browser on the computer. Thread thread = new Thread ( this ); |
Create a run method in the same class as the thread: public void run ( ) { // put the continual loop in the body } |