Flashing graphics
I'm trying to recreat the space invaders game. Everything is working out fine except my alien space ship images "flicker". I'm using a swing timer and the repaint() function. I've changed the update() function so that is is just drawing a buffered filled white rectangle so that not every pixel needs to be updated. I'm still getting flickering though. Any help would be appreciated. Thanks
[401 byte] By [
danielnya] at [2007-10-3 5:07:34]

I've changed the update() function so that is is just drawing a buffered filled white rectangle so that not every pixel needs to be updated.
Oh–oh. Overriding the update method is common in AWT graphics but we don't do it in Swing (according to the designers recommendation).
Swing gives you double buffering for free so drawing is easier than in the AWT. You can still draw to an offscreen image (in your event code, eg, a timer) and draw it in the paintComponent method but it is not always required or desirable. Another technique is to do limited repaints. See the four–argument repaint method in the Component class.
Use the paintComponent method in Swing graphics unless you want/need to draw over components and borders. See the paint method in the JComponent class for details. This is another difference between Swing and the AWT.
Are you saying don't use swing?
No. Use either one as you like.
I changed to paintComponent instead of regular paint. What excatly is the difference?
For this we look in the javadocs. The j2se 1.5 version docs [url=http://java.sun.com/j2se/1.5.0/docs/api/index.html]are located here[/url]. In the left frame scroll down to the JComponent class and click on the link. The JComponent class will load into the main frame. Scroll down to the Methods Summary section and down to the paint method. Click the link which will take you to the description of the paint method in the Method Detail section.