Developing Java Applications: A Tutorial | Creating a Custom View Class

Defining the Custom View Subclass

Place and Resize the CustomView Object

The CustomView object on Interface Builder's Views palette represents an instance of any custom subclass of NSView or of any Application Kit class that inherits from NSView. The CustomView object lets you specify the basic attributes of all view objects: their location in a window and their size.

  1. Drag the CustomView object from the Views palette and drop it in the window.

    Center it in the window beneath the text fields.



  2. Resize the CustomView using the Size inspector.

    Choose Inspector from the Tools menu, select the Size display, and enter 64 in both the width (w) and height (h) fields.

Specify the Subclass

As you did earlier with the controller object TempController, you must provide the name and superclass of your custom class. But now, instead of inheriting from java.lang.Object, your class inherits from an Application Kit class.

  1. In the Classes display of the nib file window, select the NSImageView class.

    If a class in the display has a filled-in circle next to it, you can click the circle to reveal the subclasses of that class. The path you want to follow is this:
    NSObject, NSResponder, NSView, NSControl, NSImageView.



  2. Choose Subclass from the Classes menu.
  3. Name the class "TempImageView".

There is no need to specify any outlets or actions for this class.

Important
Currently, Interface Builder lists the Objective-C set of Yellow Box classes in its Classes display. This set does not map exactly to the Java set. The release notes for the Yellow Box Java APIs ( JavaAPI.html in /System/Documentation/Developer/ReleaseNotes ) describes which Objective-C Foundation and Application Kit classes and protocols were exposed as Java classes and interfaces, and which Java classes are new. For those Objective-C classes that were not exposed, it indicates the JDK counterparts that you can use instead.

Assign the Class to the CustomView

Unlike custom controller classes, where you use the Classes>Instantiate command to make an instance, you make an instance of a custom view in Interface Builder by assigning the class to the CustomView object.

  1. Select the CustomView object.
  2. Select the Custom Class display of the inspector.
  3. Select the TempImageView class in the list provided by that display.

Notice how the title of the custom view object changes to "TempImageView."


Previous | Next
© 1998 Apple Computer, Inc.