While I do not do animation or draw very complex graphics.
I need (sort of) double buffering to draw multiple primitives. In the application, the user enters the name Shape, followed by the associated arguments, and this shape is drawn on the buffer and then on the screen. For example, the command RECT 100, 50, 200, 120 .
For perseverance, I can keep all the commands in the list and in
public void paintComponent(Graphics g) from JPanel I draw them one by one.
But this is very inefficient due to repeating the list and using a hash map each time to call (or send) the corresponding shape-drawing interface.
How and on what type of buffer can I draw? How can different methods use this buffer?
Also, is there a convenient way to cancel previous draws using a buffer? Or do I need to redraw the buffer every time I cancel?
Thanks, I do not need the full code, but the corresponding class names and a small pseudo-code are appreciated.
source share