java.applet

Java Code Example for Applet: getDocumentBase() Method

Java Code Example

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:

 C:/Vigilance/samples/bin/index.html 

Then the document base is :

 C:/Vigilance/samples/bin/index.html

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


/**********************************************************************************
 * Created on Nov, 2004 Copyright(c) https://kodehelp.com All Rights Reserved. 
 **********************************************************************************/
package com.kodehelp.java.applet;

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

/**
 * @author https://kodehelp.com
 * 
 */
public class AppletGetDocumentBase extends Applet {
	
	Image image;

	@Override
	public void init() {
		System.out.println(getDocumentBase());
		image = getImage(getDocumentBase(),"logo.png");
	}
	
	@Override
	public void paint(Graphics g) {
		g.drawImage(image, 0, 0, this);
	}

}

Leave a Comment

Your email address will not be published. Required fields are marked *