Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: I am getting to much flickerence in applet
|
Posted: May 14, 2003 2:22 PM
|
|
Flicker in an applet is eliminated usually by double buffering.
declare two class variables: Image offscreenimage; Graphics offscreen;
In your init() method, initialize an offscreen graphics components for double buffering: offscreenimage = createImage(appletwidth,appletheight);
in the applet paint method:
first do all the drawing that you normally do to the offscreen graphics context:
offscreen.setColor(Color.red); offscreen.drawString("Test Test Test",250,30); etc....
then draw the offscreen image produced to the onscreen graphics context specified in the argument of your paint method:
onscreen.drawImage(offscreenimage,0,0,this);
All the drawing which is currently causing the flickering, will be drwan to the ofscreen graphics, then the ofscreen graphics updated with the image of the offscreen graphics. This last line occurs very fast, basically eliminating flicker.
Look at the code in:
http://www.quantumhyperspace.com/SourceBank/viewCode.jsp?javaFile=QuantumClock.java
which demonstrates double buffering. There is probably some more on all this in the java tutorial.
|
|