I found this code of double buffering on internet but it has no explaination. I am a little confused in this code.
Why is the Image "i" used? What is its use if it is to be used once?
Why are we assigning changing color to Foreground color,when we already have set color?
What is g.drawImage() method doing?
Here is the code:
public void update(Graphics g)
{
if(i==null)
{
i=createImage(getWidth(), getHeight());
graph=i.getGraphics();
}
graph.setColor(getBackground());
graph.fillRect(0, 0, getWidth(),getHeight());
graph.setColor(getForeground());
paint(graph);
g.drawImage(i,0,0,this);
}
Regards