explain code and document bases if you dont know


Explain Code and Document Bases ?

If you don't know the exact URL of the image, but you do know its name and in which it's in the similar directory as the applet, you can use an alternate form of getImage() that takes a URL and a filename. Use the applet's getCodeBase() method to return the URL to the applet directory like this:

Image img = this.getImage(this.getCodeBase(), "test.gif");

The getCodeBase() method returns a URL object in which points to the directory where the applet came from.

At last if the image file is stored in the similar directory as the HTML file, use the similar getImage() method but pass it getDocumentBase() instead. This returns a URL those points at the directory that contains the HTML page in which the applet is embedded.
Image img = this.getImage(this.getDocumentBase(), "test.gif");

If an image is loaded from the Internet, it might take some time for it to be fully downloaded. Most of the time you don't need to worry about this. You can draw the Image as soon as you've linked it to a URL using one of the above methods. Java will update it as more data becomes available without any further intervention on your elements.

Load all the images your applet requires in the init() method. In particular you do not want to load them in the paint() method. If you do they will be reloaded each time your applet repaints itself, and applet performance will be abysmal.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: explain code and document bases if you dont know
Reference No:- TGS0285256

Expected delivery within 24 Hours