import java.applet.*; import java.awt.*; public class DrawImage extends Applet implements Runnable { Thread t; private Image bufferImage; private Graphics buffer; // create a graphics buffer and off screen image private int width; private int height; private Image myPicture; // create a field to store a picture public void init() { setBackground(Color.black); t=new Thread(this); t.start(); width=size().width; height=size().height; myPicture = getImage(getCodeBase(), "OptimusPrime.jpg"); // place a picture into our Image object bufferImage=createImage(width, height); buffer = bufferImage.getGraphics(); // create off screen buffer image and place it in the buffer } public void run() { while(true) { repaint(); try{ t.sleep(5); }catch(InterruptedException e){ ; } } } public void paint(Graphics g) { if (buffer == null) { // make sure the buffer was setup correctly bufferImage = createImage(width, height); buffer = bufferImage.getGraphics(); } buffer.setColor(Color.black); buffer.fillRect(0,0, width, height); // draw our background square to the buffer buffer.drawImage(myPicture, 10, 10 , null); // draw our picture into the off screen buffer g.drawImage(bufferImage, 0, 0, this); // draw our buffer image to the applet } public void update(Graphics g) { paint(g); } }