Answer:

An applet is a "little application" that can be run in the context of a Web page.

Adding Applets to a Web Page

An applet is an object whose methods are run under the control of a Web browser. The Web browser acts as a main() method and calls the applet's methods. The methods are called when a Web page containing an applet is loaded, or in response to events such as mouse clicks or menu selections.

Applets do not run by themselves. They are run in the context of a Web browser or the appletviewer of the JDK.

To include an applet on a Web page use the following set of tags:

<applet code="MyApplet.class" width="250" height="200">
</applet>

The width and height give the size of a rectangle in the Web browsers screen that will be used for the applet. You cannot omit width and height; but you can pick any reasonable values you want.

The code="MyApplet.class" part names the compiled bytecodes of the applet that will be run. With the above form of the applet tag, the bytecodes must be in the same disk subdirectory as the Web page. (For details on how to create applets and how to compile them, see Part 5 of these Notes).

QUESTION 2:

(Thought Question: ) Why must you tell the browser the width and height of the area used for the applet?