How to reduce flicking in animation?

Answer Posted / m!r@

Double Buffering

sample code of java to reduce flinking :

public void update(Graphics g) {
Graphics offgc;
Image offscreen = null;
Dimension d = size();
offscreen = createImage(d.width, d.height);
offgc = offscreen.getGraphics();
offgc.setColor(getBackground());
offgc.fillRect(0, 0, d.width, d.height);
offgc.setColor(getForeground());
paint(offgc);
g.drawImage(offscreen, 0, 0, this);

}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between wait and notify in java?

549


Is it possible to cast an int value into a byte variable? What would happen if the value of int is larger than byte?

551


What are the major drawbacks of external iteration?

578


In which language java is written?

542


Is nullpointerexception checked or unchecked?

559






Why do we create public static method in java?

582


What does function identity () do?

521


How do you allocate memory to object?

523


Is arraylist zero based?

559


What is the purpose of the main method?

545


What data type is string java?

543


If a variable is declared as private, where may the variable be accessed?

554


What are operators and its types?

578


What is java regex?

536


What is the final access modifier in java?

617