Redraw panel in timer event
I have a map with cars in it, and in order to make them move, I call repaint in a timer event-which redraws everyting. However this is not performance friendly, since the map does not have to be redrawn, just the cars in it.
So I thought about buffering the map and then call drawCars() in the timer. As a first step, I am calling drawEveryting() in a timer, instead of calling repaint of the panel. So all I did was putting the same code from repaint in drawEveryting(). However, the map is flickering a lot, even though the cpu use remains at 5%. Here the content of drawEveryting():
Graphics2D g2 = (Graphics2D)getGraphics();