Placing Java Applets on a Web Page

 

Once your applet has been compiled, it must run in a graphic window that is large enough to accommodate the pixels in the applet. The following HTML code will meet all the requirements to run the Hello.class that was written if you completed the section on writing a Java applet. Any applet will serve for this example as long as three requirements are met. If you haven't written any applets yet, you may follow the link to this lesson when you do.

  1. The defined applet window must be large enough to hold the applet or it will be cropped.

  2. The name of the file called within the HTML code must match the name of the class file exactly, including the case of the letters.

  3. The compiled class file must be in the same directory as the HTML code that is calling it (or the precise path must be specified in the HTML code.)

 


 

View of the applet's output

 

 

 

<html>
<head>

<title>Applet Page</title>
</head>

<body>

<p align="left"><font size="6">
<strong>View of the applet's
output</strong></font></p>

<p><applet code="Hello.class"
align="baseline" width="301"
height="301"></applet></p>


</body>

</html>



.



<This line places a label above the applet

.

< The Applet is inserted here with a
window of 301 pixels in height and width.
Be sure you select an appropriate size
for the applet window. Check that you
are calling the correct class file and that
it has been saved in the same directory.

 

When you load the HTML file in your browser the applet will execute within the window.

This generic HTML page can be used to display all of your applets (providing they fit in a 301x301 pixel window). If not you must determine how many pixels are needed for your window.

Hit the "Return to previous page" or "back" button on your browser

Go to the next topic: The Graphics Coordinate System

Back to the Table of Contents