The following is a skeleton for a component class supporting animation. Basically, the steps are:
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComponent; import javax.swing.Timer; public class ComponentName extends JComponent implements ActionListener { private Timer timer; // timer instance variable . . . // other instance variables (fields) . . . /** Starts the timer going by constructing a Timer object with the frequency (in milliseconds) of Timer activations and the object ('this') that will be handling the Timer events */ public void animate() { timer = new Timer( (int)Math.round(deltaT * 1000), this ); timer.start(); } /** Processes a Timer activation event */ public void actionPerformed( ActionEvent e ) { // Code to update the state of the object // should go here . . . repaint(); // repaint the component on the screen } }