I have a this loop in class collection
which repaint()
JPanel continiously
while(loop) {
imageicon = (ImageIcon) ois.readObject();
image = imageicon.getImage();
cjpanel.tempimage = image;
cjpanel.repaint();
Thread.sleep(100);
}
and cjpanel
extends JPanel where i have overridden paintComponent()
and i am using Double buffering
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
tempimage.getScaledInstance(dim.width, dim.height, Image.SCALE_FAST);
bufferGraphics.clearRect(0,0,dim.width,dim.width);
bufferGraphics.drawImage(tempimage,0,0,dim.width,dim.height, null);
g.drawImage(offscreen,0,0,this);
}
my problem is repaint
is always two frames behind while loop. i.e if image 4
is in while
loop then paintComponent()
is drawing `image 2.
So how can i Speed up repaint
or stop new repaint
before previous repaint
is done?
UPDATE
when I changed the size of image from ObjectInputStream it is working fine. I think it has to do something with image size..