My appplets flicker

I have developed an applet which has an image in the background and there is another image over it, user can move the forground image by mouse, the problem is when the image is moved by the mouse , the background flicker as it is repainting. I am using the Canvas class, and have set the image on its background. Can anybody help me with it.

here is the code

public void paint(Graphics g) {

if (isOpaque())

{

super.paint( g );

if ( image != null )

{

int width = getWidth(), height = getHeight();

g.setColor( getBackground() );

g.fillRect( 0, 0, width, height );

if ( fillEntireArea )

g.drawImage( image.getImage(), 0, 0, width, height, this );

else {

if ( !tileImage ) {

g.drawImage( image.getImage(),

( width-image.getIconWidth() )/2,

( height-image.getIconHeight() )/2,

this );

} else {

int tileW = image.getIconWidth();

int tileH = image.getIconHeight();

int xpos, ypos, startx, starty;

for ( ypos = 0; height - ypos > 0; ypos += tileH ) {

for ( xpos = 0; width - xpos > 0; xpos += tileW ) {

image.paintIcon( null, g, xpos, ypos );

}

}

}

}

}

}

if (imgw < 0) {

imgw = curimage.getWidth(this);

imgh = curimage.getHeight(this);

if (imgw < 0 || imgh < 0) {

return;

}

}

if (scalew < 0) {

if (rotation == 0) {

scalew = imgw;

scaleh = imgh;

} else {

Rectangle rect = new Rectangle(0, 0, imgw, imgh);

rotfilters[rotation].transformBBox(rect);

xoff = rect.x;

yoff = rect.y;

scalew = rect.width;

scaleh = rect.height;

}

scalew = (int) (scalew * hmult);

scaleh = (int) (scaleh * hmult);

xoff = (imgw - scalew) / 2;

yoff = (imgh - scaleh) / 2;

}

if (imgw != scalew || imgh != scaleh) {

g.drawImage(curimage, xadd + xoff, yadd + yoff,

scalew, scaleh, this);

} else {

g.drawImage(curimage, xadd + xoff, yadd + yoff, this);

}

}

[2119 byte] By [NexGenComa] at [2007-10-2 5:21:01]
# 1
I guess you are using java.applet.Applet to create the Applet? Try javax.swing.JApplet instead. Swing components are double buffered and flickering is avoided.
PatrikOlssona at 2007-7-16 1:23:01 > top of Java-index,Desktop,Core GUI APIs...