Tutorial: Building your first application with JBuilder

This brief tutorial will show you how to create a simple Hello World application or applet. To make a printed copy of this tutorial, click the Print icon .


Step 2

Step 1: Creating your project

The Project Wizard creates a project skeleton.
  1. Choose File|Close All to close any open projects or files.

  2. Choose File|New and double-click the Application icon. To create an applet instead of an application, double-click the Applet icon instead.
    The Project Wizard is displayed. (JBuilder requires that you have a project open before you create an application or applet.)

  3. For both applications and applets:
    1. Enter JBuilder\myprojects\hello\hello.jpr in the File text field. Use the letter of the drive where JBuilder is installed.
    2. Enter HelloWorld in the Title field.
    3. You can also enter your name, company name, and a description of your application or applet in the appropriate fields.
      The Project Wizard should look like this:

      Note: The only difference in the Project Wizard for application or applets is in the title bar display - for applications, the title bar displays "(for Application Wizard);" for applets, it displays "(for Applet Wizard)."

  4. For both applications and applets, click the Finish button.
    The AppBrowser appears, showing the HTML page "Project Notes" with the information that you entered in the Project Wizard. The AppBrowser display is identical for applications and applets.


Step 1 Step 1 Step 3

Step 2: Generating your source files

The Application and Applet Wizards create the .java files to go into the project skeleton created by the Project Wizard. The Applet Wizard also creates the HTML file that runs your applet.

The wizard automatically appear after you click the Finish button in the Project Wizard.

To create:

Generating source files for an application

To generate source files for an application, follow these steps:
  1. Enter Hello in the Class field. This is a case-sensitive Java class name. You don't have to enter the package name; you entered it in the Project Wizard.

  2. Make sure that the Use Only Core JDK and Swing Classes option is unchecked.

  3. Check Generate Header Comments so that the information you entered for the Project Wizard will appear at the start of the all source files that the Application Wizard generates.
    The Application Wizard should look like this:

  4. Click the Next button.
    The Step 2 dialog box appears.

  5. Enter HelloFrame in the Class text field (for Frame Class).

  6. Enter Hello World in the Title text field (for Frame Style).

  7. Check all check boxes for additional application features. The basic code to support these features is generated by the Application Wizard.
    The Application Wizard should look like this:

  8. Click the Finish button.
    The new .java classes, .html files, and .gif files are added to your project.

  9. Choose File|Save All to save the source files.

Generating source files for an applet

To generate source files for an applet, follow these steps:
  1. Enter Hello in the Class field. This is a case-sensitive Java class name. You don't have to enter the package name; you entered it in the Project Wizard.

  2. Make sure that the Use Only Core JDK and Swing Classes option is unchecked.

  3. Check the other three Applet Style checkboxes.
    The Applet Wizard should look like this:

  4. Click the Next button.
    The Step 2 dialog box appears, where you enter applet parameters.

  5. Enter test in the Name field.

  6. Choose String from the Type drop-down list.

  7. Enter test_var in the Variable field.
    The Applet Wizard should look like this:

  8. Click the Finish button. Click Yes to overwrite the hello.html file created by the Project Wizard. (Although there is a Step 3 dialog box for the Applet Wizard, clicking Finish at this point accepts the defaults for that step.)
    The new .java class and .html files are added to your project.

  9. Choose File|Save All to save the source files.

Step 1 Step 2

Step 3: Compiling and running your application

Now, compile and run the application or applet that you have built.
  1. Choose Run|Run, press F9, or click to compile and run your application.
    Your application or applet is displayed. Applets are displayed in the Applet Viewer. In this example, the applet only consists of a title bar; it does not contain a menu bar or button bar. Your application should look like this:

    If you've created an application, you can click any of the buttons on the toolbar. However, because no events are hooked up to these buttons, nothing happens.

  2. Choose File|Exit to close your application. Click the close box to close your applet.

Next Steps

To learn more about using Borland JBuilder: