Creating Variables
In this section, you'll declare individual variables in your code file (Main.java) to hold the name, e-mail address, and comments entered by a single guest. Later on, you'll structure this information differently in order to work with data from multiple users.WebObjects Builder allows you to declare variables without having to edit your source file directly. At the bottom of the window there is a pull-down menu called Edit Main.java. It has three items:
- Add Variable/Method allows you to add a key to your source file. A key can be either an instance variable or a method that returns a value.
- Add Action allows you to add the template for an action method, which is a method that takes no parameters and returns a component (the next page to be displayed).
- View Source File opens the source file in a Project Builder window.
- Choose Add Variable/Method from the pull-down menu.
- Type guestName in the Name field.
- To specify the variable's type, select String from the pop-up menu (or you can type String directly in the box.
- Click Add.
- Create the variables email and comments in the same way (they are also of type String.)
The Add Variable/Method panel opens.
You have just created a variable called guestName of type String. It appears in the first column of the object browser. A declaration for guestName also appears in Main.java, which you'll edit later.
Table of Contents Next Section