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.
- Choose File|New and double-click the Project icon to create a new Java project.
- Edit the File field to read:
[d:]\JBuilder\myprojects\TextEdit\TextEdit.jpr
where [d:] is the drive in which JBuilder is installed.
- 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,
- Select TextEdit.jpr in the Navigation pane.
- Choose File|Project Properties from the main menu.
- 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.
- On the Project Properties Code Style tab, check "Standard adapter" for the Event Handling option.
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.
- On the Code Style tab, make sure "Use Beans.instantiate" is unchecked, then press the OK button to close the Project Properties dialog box.
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.
- Choose File|New again and double-click the Application icon to open the Application Wizard.
- Change the class field on Step 1 of the Application Wizard:
Class: TextEdit
- Make sure "Use only core JDK and Swing classes" is unchecked on Step 1, then click the Next button.
- Change the following fields on Step 2:
Class: TextEditFrame
Title: TextEdit
- Check all the options on Step 2. (Notice what each option is as you check it off.)
- Click the Finish button.
- 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.
- The UI Designer appears in the Content pane.
- Component Tree appears in the Structure pane.
- The Inspector appears at the right of the AppBrowser.
JBuilder in Design mode: