I cant find any answer to this. I am trying to use active painting in loop in Java. I create a new BufferedImage
and in my paint method get its graphics, draw to its graphics normal Image
and also various shapes like fillRect() etc.
Then I draw the BufferedImage
to JPanel
(with variable name canvas) graphics.
Graphics gr = buffer.createGraphics();
gr.drawImage(img, 0, 0, 500, 500, null);
for (int i = 0; i<200; i++){
gr.drawOval(i*10,i*20,50,50);
etc.
}
gr.dispose();
canvas.getGraphics().drawImage(buffer, 0, 0, 500, 500, null);
Why do I see in the JPanel all the shapes drawn but without Image , which comes only with delay I thought that first everything is drawn to BufferedImage and that is subsequently drawn on another graphics at once (isnt that whats buffers about?). Can someone please explain this to me? What thread is supposed to draw stuff on graphics object? In which is this Image drawing running (when using active rendering, not calling paintComponent())