Inserting applets

After you have added applets to a Web project, you can then insert the applets into your Web pages.

Create a Web project

To insert a Java™ applet into a Web page:

  1. Import all of the files that compose the applet into a subfolder in the Web project that contains the Web page. This typically includes any class files, image files, and any other files specified in the class files.

  2. Place the cursor in the appropriate position in the Web page.

  3. Select

    Insert | Others | Java Applet. The

    Insert Applet dialog box opens.

  4. At a minimum, type the class file name in the

    Code field, the applet subfolder name in the

    Code base field, an explanation of the applet in the

    Alternative text field, and the size of the applet in the

    Width and

    Height fields. Choose any additional items or layout values that you want to assign to the applet.

    Click the Browse button next to the

    Code field to select a Java applet class from a workbench project, or import a class or JAR file from your file system. New resources are copied to the same folder as the HTML or JSP file that an applet is being inserted into if they are not already included in the current project.

  5. On the

    Parameters tab, click the

    Add button. A new (blank) parameter is added to the list. Enter the parameter name in the

    Name field and the corresponding value in the

    Value field. Press the ENTER key to finish editing the parameter. Repeat this step for any number of parameters, or update the list of parameters using the other push buttons.

  6. Click OK to insert the Java applet, and save the file that the applet was added to.

    The applet is indicated by an alternative image. You can view the actual applet in a Web browser.

    You can also view the applet by using the

    Preview tab.

Restriction: The Java Resources folder,

Java Resources:src by default, in a Web project is for server-side classes, so the source code for applets cannot be placed in this folder. Therefore the following is recommended when developing applets:

  1. Create a Java project for applets and create the applet classes in the project.

  2. Copy applet class files to the Web content folder. Do not copy them to the WEB-INF folder since that folder is for server-side classes only. You will need to change the Enterprise Explorer view filters by selecting

    Filters from the Menu drop-down list.

  3. Insert an applet in a Web page by selecting

    Insert | Others | Java Applet in Page Designer. At that time set the appropriate code and codebase attributes.

    For example, if your applet class is aaa.bbb.AnApplet and the file structure is as follows:

    • WebContent/index.html

    • WebContent/MyApplets/aaa/bbb/AnApplet.class

    • code is aaa.bbb.AnApplet
    Then the applet tag in index.html should contain:

    • codebase is MyApplets

 

Related concepts

Java applets in Web pages

 

Related tasks

Adding scripts, controls, and effects to Web pages

Adding server-side includes to Web pages