Solution: Override update()
The culprit is update(), a method called by Java with each call to paint().
We can eliminate the flicker by merely overriding update:
public void update (Graphics g){
paint(g);
}
Note that we call paint() and don’t merely create a no-op. This avoids premature garbage collection of the Graphics object.