Created
January 18, 2019 20:08
-
-
Save ny83427/58787b03c75479715f148b906dd6c1da to your computer and use it in GitHub Desktop.
Double Buffer Avoid Flashing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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