Step 02

Tutorial: Building a Java text editor

About this tutorial

Step 1: Creating the project

Using the Project Wizard

To start this tutorial, you first need to create a project which contains the necessary files for building your user interface. You'll use two of JBuilder's wizards to speed up this process, the Project Wizard and the Application Wizard.

  1. Choose File|New and double-click the Project icon to create a new Java project.

  2. Edit the File field to read:

    [d:]\JBuilder\myprojects\TextEdit\TextEdit.jpr
    where [d:] is the drive in which JBuilder is installed.

  3. Choose Finish.

Selecting the project's code style options

Before you go on, make sure you select the same code style options we used for JBuilder generated code. You do this in the Project Properties dialog box.

To change the code style options,

  1. Select TextEdit.jpr in the Navigation pane.
  2. Choose File|Project Properties from the main menu.
  3. Click the Code Style tab.

Choosing the event handler type

First, you need to choose which style event handler to generate. JBuilder can use either anonymous inner classes, or separate adapter classes. In this tutorial, we use separate adapter classes.

Note: Regardless of which style event handler method you use, the code you put inside the method will be the same.

For more information on the differences between event handler styles, see Choosing which type of event handler use in "Working with events" in the Quick Start.

Choosing how to instantiate objects

Next, you need to choose which method to use for instantiating objects. JBuilder gives you the option of instantiating objects using Beans.instantiate(), as well as the prior technique of using the new keyword. This tutorial uses new.

For more information on using Beans.instantiate(), see Instantiating serializable JavaBeans under "Serializing JavaBeans" in the Component Writer's Guide.

Using the Application Wizard

Now let's add the application files to the project.

  1. Choose File|New again and double-click the Application icon to open the Application Wizard.

  2. Change the class field on Step 1 of the Application Wizard:

    Class: TextEdit

  3. Make sure "Use only core JDK and Swing classes" is unchecked on Step 1, then click the Next button.

  4. Change the following fields on Step 2:

    Class: TextEditFrame
    Title: TextEdit

  5. Check all the options on Step 2. (Notice what each option is as you check it off.)

  6. Click the Finish button.

  7. Select TextEditFrame.java in the Navigation pane (upper left), and click the Design tab at the bottom of the AppBrowser window to display the visual design tools.

    JBuilder in Design mode: