Closed Nisnow closed 5 years ago
What class is the problem occurring in?
This may have to do with how we are rendering at the same time as Swing is calling painComponent so it ends up displaying 'canvas' before anything is drawn to it. We can take a double-buffered approach to solve this issue. In the concept of double buffering, we have 2 buffers(images): a front buffer and a back buffer. The front buffer is the image being displayed on the screen and the back buffer is the image that is currently being constructed/rendered. After the back buffer is complete, "swap" the buffers so then the back buffer becomes the front buffer and vice versa. This only requires you to add one BufferedImage and a display method which swaps the buffers.
Should come up with a better clear() method of sorts to prevent this.