I am trying to set an image as a background for the applet. whenever the paint method is called, it redraws the image again; and this causes flickering. how can I make the image be drawn only once?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main extends Applet {
Image background;
@Override
public void init() {
setSize(800, 600);
try {
System.out.println(getCodeBase());
background = ImageIO.read(new File("1.jpg"));
} catch (IOException ex) {
System.out.println("Error reading the image");
}
}
@Override
public void paint(Graphics g) {
g.drawImage(background, 0, 0, this);
}
}