Hello,
i want to draw in a canvas which listens to mouse events. so far so good, but if i get a drag-event the canvas begins with flickering. i have read about a bufferstrategy but i failed to use it with the canvas. the error message was something about “need a valid peer”. so i am using a buffered image but the flickering is still there.
Here is the (pseudo-)code of the paint function of this canvas:
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D)g;
if(firstTime){
// create BufferedImage
// create Graphics from BufferedImage
firstTime = false;
}
//clear Image
// run through vector
// draw element of vector to Graphics of BufferedImage
// Drawing the buffered image to the screen
g2.drawImage(aBufferedImage, 0, 0, this);
}
i would be happy if anyone has a hint for me.
thanks