In order to display a Java applet you will need to create an html file that will execute the applet. You can then view this html page either using Java's applet viewer or using a Java-compatible browser. It is assumed that you have some knowledge of html programming.
Creating an html page for Java applets is relatively easy. You only need to include the standard html headers and closers along with one extra item. To create an html page for the hi applet, create a file containing the following:
<html> <body> <applet code = "hi.class" width=300 height=200> Please get a Java compatible browser to see this. </applet> </html>
The applet code label (<applet code = {filename} ...>). This line tells the browser what file contains your Java code and sets up the applet's size. Also, command line parameters for the applet can be passed in from here.
In this example, the browser will look in the current directory of the html document for a file called hi.class and will create an applet drawing area with width 300 and height 200 (in pixels). The line following the <applet> tag, Please get a Java compatible browser to see this., will let users who do not have a Java compatible browser know that something would be displayed if they did have a Java-compatible browser. Without this line most browsers would display nothing. A Java-compatible browser will display the applet (execution) rather than the message.
If you wish to compare the above html source with the html source used in the tutorial for the hi.java program, click on hi.html to view the hi applet's page. Then view the source for the applet's page using your browser's source option. (To return to this page, terminate the source view (e.g., on Netscape you quit the source window) and use the Back option on the browser to return here.) To view the applet (and source) click on hi.html. The source for the html page used in the tutorial is similar to the source above, with adjustments for file names and other minor changes.
(Note: If you are using a file system where there are permissions, make sure that your .html and .class files are readable by the world if you want your applet to be executable by others.)
To view the applet using Java's applet viewer, use the command