Skip to content

Instantly share code, notes, and snippets.

@ny83427
Created January 18, 2019 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ny83427/58787b03c75479715f148b906dd6c1da to your computer and use it in GitHub Desktop.
Save ny83427/58787b03c75479715f148b906dd6c1da to your computer and use it in GitHub Desktop.
Double Buffer Avoid Flashing
private Image bgImage;
@Override
public void update(Graphics g) {
if (bgImage == null) bgImage = this.createImage(WIDTH, HEIGHT);
Graphics bg = bgImage.getGraphics();
bg.setColor(Color.BLACK);
bg.fillRect(0, 0, WIDTH, HEIGHT);
this.paintComponent(bg);
}
@Override
protected void paintComponent(Graphics g) {
// painting stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment