How to load image in Applet class in Java?

DeeKay July 19, 2011 at 12:14 am · java.applet

Java code to load applet with image in it as background

/****************************************************************************************
 * Created on 07-2011 Copyright(c) http://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.java.applet;

import java.applet.Applet;
import java.awt.*;

/**
 * Created by http://kodehelp.com
 * Date: 7/18/11
 */
public class ShowImageInApplet extends Applet {
    Image image = null;
    public void init(){
        System.out.println(getDocumentBase());
        image = getImage(getDocumentBase(),"demo.jpg");
    }

    public void paint(Graphics graphics){
        graphics.drawImage(image,0,0,this);
    }

}