Graphics, AWT, Swing I part
Visit us here and  you will find
much more tips!
Receive our  newsletter with new tips!  Almost 6,000 subscribers (by June 2001) can not be wrong! 
They read our tips every week! 
 To subscribe to The Java FAQ Daily send empty e mail to:
javafaq tips subscribe@topica.com
  or visit at:
http://www.topica.com/lists/javafaq tips/
 Graphics, AWT, Swing
How can I minimise "Flicker" in animation? Solution 1:
Answer: Solution 1: 
Override update() : Flickering in animation occurs because default update() method
clears the screen of any existing contents and then calls paint(). To reduce flickering,
therefore, override update(). Here is how just add the following code to your applet: 
public void update(Graphics g) {
    paint(g);
}
What the update is now doing is just calling paint() and not clearing it, a further
refinement to the above will be to override update() method and painting only the
region where the changes are taking place. Here is how: 
public void update(Graphics g) {
    g.clipRect(x, y, w, h);
    paint(g);
}
Solution 2  will be described tomorrow
 How can I minimise "Flicker" in animation? Solution 2:
Solution 1 was described in our tip yesterday
Solution 2: 
Use double buffering : double buffering is the process of doing all your drawing to an
offscreen and then displaying the entire screen at once. It is called double buffering
because there are two drawing buffers and you switch between them. Use double
buffering only if the above solution alone does not work. The following code snippet
describes how to do it. 
Image offscreenImage;
file:///F|/a_jsite/350_tips/graphics I.htm (1 of 5) [2001 07 08 11:24:55]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved