As expected, if you don’t add extra code, drawing things that move on the applet surface will result in flickering. It’s ugly, it hurts eyes and it just looks unprofessional.
The remedy is simple and works with all technologies and platforms – draw to the off-screen buffer and then just slap the whole buffer to the screen in one go. This is very easy to implement in Java since you can get a Graphics class out of the Image (that represents your off-screen buffer) and then when you draw to this Graphics everything is drawn to the Image.
Except that the flickering is still there. Just like with Windows API applications, the problem is that there is an “erase background” step. In Windows API the culprit is WM_ERASEBACKGROUND message, in Java it’s the update method of the Applet class. Override update method and only call your paint method – it’s that simple.
By the way, don’t forget to recreate the off-screen buffer when the applet’s size changes. Most of the applets are fixed size, but some could be detached from the browser and then they might become resizable.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5