Java Code Example for Applet: getDocumentBase() Method

DeeKay April 19, 2011 at 5:38 pm · java.applet

getDocumentBase() emthod of Applet class returns the URL of the document in which this applet is embedded. For example, suppose an applet is contained within the document:


Then the document base is :


Below java code show how to get the document base in Applet :

 * Created on Nov, 2004 Copyright(c) All Rights Reserved. 

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

 * @author
public class AppletGetDocumentBase extends Applet {
	Image image;

	public void init() {
		image = getImage(getDocumentBase(),"logo.png");
	public void paint(Graphics g) {
		g.drawImage(image, 0, 0, this);