

Creating a Guest List
To store the information from all guests that have accessed the application, you'll create an application variable called allGuests, which exists for the life of the application.- In Project Builder, select Classes in the first column of the Browser. Then select Application.java from the second column.
The application's code appears in the window. The following figure shows the code generated by the Wizard, along with code you will add.
- After the call to super, enter this code:
allGuests = new MutableVector();
This statement initializes allGuests to be a new object of class MutableVector. This class is the Java equivalent of the Objective-C class NSMutableArray, which provides an interface that allows you to add, change and delete objects from an array.
- At the top of the Application class definition, enter this declaration:
protected MutableVector allGuests;
This declares allGuests to be of type MutableVector. Declaring it protected means that it is accessible only from this class or one of its subclasses. It is standard object-oriented practice for a class to prevent other classes from directly manipulating its instance variables. Instead, you provide accessor methods that other objects use to read or modify the instance variables.
- Add the accessor methods addGuest and clearGuests, as shown in the figure.
The addGuest method adds an object of class Guest to the end of the allGuests array, using the MutableVector method addElement (its Objective-C equivalent is addObject).
- Save Application.java.
Table of Contents
Next Section