Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Legacy Documentclose button

Important: The Java API for Cocoa is deprecated in Mac OS X version 10.4 and later. You should use the Objective-C API instead. For a tutorial on using Cocoa with Objective-C, see Cocoa Application Tutorial.

Interconnecting the ConverterController Class and the User Interface

The following sections show how to connect the Converter Controller user interface and the ConverterController class to each other.

In this section:

Create an Instance of the ConverterController Class
Connect the ConverterController Class to the Text Fields
Connect the Convert Button to the ConverterController convert Action Method


Create an Instance of the ConverterController Class

As the final step of defining a class in Interface Builder, you create an instance of the ConverterController class and connect its outlets and actions. To carry out this task, perform these steps:

  1. Select ConverterController in the Classes pane in the MainMenu.nib window.

  2. Choose Instantiate ConverterController from the Classes menu. The instance appears in the Instances pane as shown in Figure 1-20. Notice that the instance has a yellow badge with an exclamation point next to it. This means the instance contains unconnected outlets.


    Figure 1-20  A newly instantiated ConverterController instance

    Figure 1-20 A newly instantiated ConverterController instance

Connect the ConverterController Class to the Text Fields

By connecting it to specific objects in the interface, you initialize its outlets. ConverterController uses these outlets to get and set values in the user interface. Follow these steps to connect the ConverterController instance to the user interface:

  1. In the Instances pane in the nib file window, Control-drag a connection from the ConverterController instance to the Exchange Rate text field.

  2. Interface Builder displays the Connections pane of the inspector. Select the outlet that corresponds to the first field, rateField.

  3. Click Connect, as shown in Figure 1-21.


    Figure 1-21  Connecting ConverterController to the rateField outlet

    Figure 1-21 Connecting ConverterController to the rateField outlet
  4. Following the same steps, connect ConverterController’s dollarField and amountField outlets to the appropriate text fields.

Connect the Convert Button to the ConverterController convert Action Method

Follow these steps to connect the user interface elements in the Currency Converter window to the methods of the ConverterController class:

  1. Control-drag a connection from the Convert button to the ConverterController instance in the nib file window.

  2. In the Connections pane in the nib file window, make sure the Target/Action pane is displayed.

  3. Select convert() in the Actions in ConverterController list and click Connect.

  4. Save the nib file.



< Previous PageNext Page > Hide TOC


Last updated: 2006-10-03




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice