Search code examples
javaanimationappletdrawingappletviewer

Java applet only updates at 10 fps


One of my recent Java assignments (High school course...) is to make an applet where a border is drawn and a ball moves around the screen bouncing on the borders. I have Fraps installed and it reports that the applet is only running at a mere 10 fps, which makes the animation look extremely mediocre.

My original way of drawing the animation:

  1. call my method: drawScreen() in paint()
  2. have a Thread.sleep(1000/frameRate) pause in drawScreen() for the frame rate, which is passed from the html
  3. call repaint()

This worked wonderfully well and the applet ran like a dream... Until I saw the grading sheet, where it said that I must not redraw the screen each time (Maybe it's because the computers are unusually slow and my friends have been complaining that their applets flicker enough to cause eye discomfort, and a lot of tearing all over the place), and I have to draw a ball, then draw another ball the same colour of the background to cover it up, calculate the coordinates, and repeat until the applet quits

The problem with this is that

  • repaint() can't be called
  • my animation is capped at 10 fps
  • there's no threads available to respond to me clicking close on the appletviewer, or anything else in the applet/viewer.

Is there a way for my animation to run above 10 fps without using repaint()?


Solution

  • Turns out I needed to either implement double buffering or run the applet in a double buffered browser. AppletViewer limited the animation to 10 fps 'cause it doesn't automatically buffer the applets and I was running the applet inside it all this time.