Timers and Graphics

There are various methods to get something to move on the screen:

Game Loop with Sleep

The basic idea is shown below. Every thing is set up properly, then the main game loop is entered. This keeps on looping until isPlaying is set to false. The loop does various updating of the game. It also draws the graphics and then sleeps for a certain amount of time. The exact amount of time depends on processing and the load on the computer. It will always be at least SLEEPTIME milliseconds, but it may be more.

	/***** Constants *****/
	static final int SLEEPTIME = 5;
	/***** Global (instance) Variables ******/
	Ball ball;
	int lives = 4;
	boolean isPlaying = true;

	/****** Constructor ********/
	BallAnimationSimple() {

		//Main Game Loop
		while (isPlaying) {		
			drawGraphics();//all graphics is drawn here
			//this probably includes a jpanel.paintImmediately(0,0,SCRW. SCRH); or else just a jpanel.repaint();

			try {
			} catch (InterruptedException e) {}
			if (lives <= 0) isPlaying = false;
			if (time == 10) isPlaying = false;	//you only have 10 seconds
			//a KeyListener could also be used to end the game if you type 'Q' but that wouldn't go here
		JOptionPane.showMessageDialog(null, "Game Over", "The End!" , JOptionPane.PLAIN_MESSAGE);