This section of the tutorial describes the basic steps for creating a custom view and, more specifically, shows how to create a sublcass of an Application Kit class that itself inherits from NSView. In this section, you will add a custom "image view" to the user interface you created in the first part of this tutorial. This custom object will respond to messages from the controller object, TempController, and change its image depending on the temperature entered. Here's what the final TemperatureConverter application will look like:
The behavior that your custom view object adds to its superclass, NSImageView, is trivial. You could just as well accomplish the same behavior by sending messages to an "off-the-shelf" instance of NSImageView. But the subclass illustrates the basic procedure for making subclasses of Yellow Box classes that don't inherit from java.lang.Object.
Creating a Subclass of NSView summarizes the procedure and provides example code for creating a subclass of NSView whose instances can draw themselves. This example subclass can replace the one you will create in this section, because it draws graphical shapes instead of displaying images when the temperature changes to another range.
Previous | Next
© 1998 Apple Computer, Inc.