An applet runs from within an HTML page, and is created with the classes in the Java API. Your applet must extend java.applet.Applet, and typically uses the classes in the java.awt package to provide a graphical user interface.
Note Before you use the following procedure to create an applet, close any projects that you may already have open. (On the File menu, click Close All.)
To create an applet
Note Renaming the Applet1.java file does not rename the associated class in the source code, and vice versa. You must manually change all instances of the old name. (Note that you can create an empty project and then add a class with the Class template. This two-step process allows you to name the class before it is created; however, the Class template does not provide the basic code framework for an applet.)
The Applet template already provides some sample functionality. You can view this sample code in the Text editor.
To view the sample code in the applet
init
method. init
method simply calls initForm
and usePageParams
. Use Class Outline to locate the initForm
method:initForm
. The insertion point immediately moves to the initForm
method. initForm
method initializes the background and foreground colors, and adds a java.awt.Label control to the applet. usePageParams
. This method retrieves the value of the <PARAM>
tags from the associated HTML page, and sets the background color, foreground color, and label text to these values. If usePageParams
is unable to retrieve the <PARAM>
values, then default values are used.For information about modifying your code in the development environment, see Editing Code.
After you build your applet, you can launch the associated HTML page from the development environment or simply open the HTML page in your browser.
To build and run your applet
Note To run the applet without an HTML page, you can use JVIEW from the command line. At the command prompt, type jview /a Applet1
from the directory location of your project. When the /a
option is specified, the Applet Viewer is launched to display your applet.