Tutorial: Building an applet

This tutorial steps you through creating an AWT applet using the JBuilder integrated development environment (IDE). For more information on the IDE and its components, see "JBuilder environment" available from the Help menu.

The tutorial shows how to:

Tip: The applet source code is provided at the end of the tutorial. The FirstApplet sample is available in samples/Tutorials/FirstApplet in your JBuilder directory.

Important: Before beginning this tutorial, read the overview which discusses important applet issues.

For information on documentation conventions used in this tutorial, see "Documentation conventions." For additional suggestions on improving this tutorial, send email to jpgpubs@inprise.com.


Step 1

Overview

It's important to remember when designing applets that browser support for Java is limited. As of this writing, Internet Explorer and Netscape support JDK 1.1.5. The browsers do not presently support Swing components, introduced in JDK 1.1.7, although they may in the future. If you are creating your applets with a more recent version of the JDK, you must be very careful to use components that the browsers support. For example, if you develop your applets strictly with AWT components, in most cases your applets will run. There may be changes in the AWT components (for example, JDK 1.1.x may have slightly different features than JDK 1.3) and you may have to modify your applet code accordingly. You can troubleshoot your applet in the browser by checking the Java Console error messages. The safest way to design your applet is by using AWT components and the JDK that the browser supports.

Note: Browsers that support JDK 1.1 include Netscape 4.06 and later and Internet Explorer 4.01 and later. JDK version support may vary by platform.

Another option is to design your applets using the current JDK and Swing components and provide your users with the Java Plug-in. This is usually only possible within a controlled environment, such as a company intranet. Browsers supported by the Java Plug-in, which provides the browser with the Java 2 SDK 1.3 Runtime Environment (JRE), can run JDK 1.3-based applets. There are several additional steps involved in developing applets that run with the Java Plug-in. Visit the Java Plug-in Home Page at http://www.javasoft.com/products/plugin/index.html for more information.

Although browsers support only JDK 1.1.5, in this tutorial we will use JDK 1.3. The applet will still run, however, because we are carefully selecting the components that we use. We are designing only with AWT components and avoiding any new JDK 1.3 features.

Important: For information on running JDK 1.1.x and 1.2 applets in JBuilder, see the "Runtime" topic in "Release Notes" (Help|Release Notes).

The "Good Evening" applet you create in this tutorial contains a drop-down list of language choices. When you select a language, such as German, the panel below the selection changes to the German translation of "Good Evening": "Guten Abend."

When you finish the tutorial, your applet will look similar to this:

GoodEvening applet

For the complete applet code, see the "Applet source code" at the end of the tutorial.

For in-depth information on applets and deployment, see "Working with applets" and "Deploying Java programs" in Building Applications with JBuilder.


OverviewStep 2

Tutorial: Building an applet

Step 1: Creating the project

Before beginning this tutorial, read the "Overview" which discusses such important applet issues as browser support, JDK versions, and applet components.

Before creating your applet, you need a project in which to store it. The Project wizard creates one for you:

  1. Choose File|New Project to open the Project wizard.

  2. Make the following changes to the project and directory names in Step 1 of the Project wizard.

  3. Accept all other defaults. Note the root path where the project is saved.

    Note: Projects in JBuilder are saved by default in the /[home]/jbproject directory. It is recommended that only advanced users change this default path.

    For more information on projects, see "Creating and managing projects" in Building Applications with JBuilder.

    Project wizard Step 1

  4. Click Next to go to Step 2 of the Project wizard.

    Project wizard Step 2

  5. Accept the defaults in Step 2 for the project, source, backup, and output paths and the JDK version. Note where the project, class, and source files will be saved. Also note that the Make Project Notes File option is checked. This option creates an HTML file that contains the project information completed in Step 3 of the wizard.

    Tip: If you prefer to create your applet using an earlier verion of the JDK, change the JDK version in this step. Although Foundation does not support JDK switching, you can edit the existing JDK in the Configure JDKs dialog box (Tools|Configure JDKs). For JDK 1.1.x, you will also need to download the JDK 1.1.x-specific version of the JFC.

    See also:
    "Setting project properties" for information on switching or editing the JDK
    "Runtime" topic in the "Release Notes" (Help|Release Notes) for information on running JDK 1.1.x and 1.2 applets in JBuilder
    "How JBuilder constructs paths" and "Where are my files?" in "Creating and managing projects" in Building Applications with JBuilder

  6. Click Next to go to Step 3 of the wizard.

  7. Make the following changes in the appropriate fields of Step 3:

  8. Click the Finish button.

    The wizard creates a project file and a project notes file, FirstApplet.jpr and FirstApplet.html, that appear in the project pane of the AppBrowser. Double-click the HTML file to see the project notes in the content pane.

    Note: Projects in JBuilder are saved by default in the /[home]/jbproject directory. Although this can be modified, we recommend that new users use the default directories.

    JBuilder Project

Changing the project properties

Now, let's change one of the project properties for this project.
  1. Select Project|Project Properties and click the General tab.
  2. Uncheck the Enable Source Package Discovery And Compilation option. In most cases, it's best to leave this option on. For a description of this option, press the Help button on the General page.

See also: "Setting project properties"

Overview Step2