Monday, December 19, 2011

Get Applet's Document URL or Directory Base

package org.best.example;

    /*
            Get Applet's Document URL or Directory Base Example
            This java example shows how get the applet's HTML document URL or
            document base using getDocumentBase() method of Java Applet class.
    */         
    
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.net.URL;
    
    /*
    <applet code="GetDocumentBaseExample" width=200 height=200>
    </applet>
    */
    
    public class GetDocumentBaseExample extends Applet{
    
            public void paint(Graphics g){
                  
                    /*
                     * To get Applet's HTML Document directory URL or the document base use
                     * String getDocumentBase()
                     * method of Java Applet class.
                     */
                  
                    URL appletDocDir = getDocumentBase();
                    g.drawString(appletDocDir.toString(), 50, 50);
                  
            }
    }

No comments: