Java Reference
In-Depth Information
CHALLENGE 18.1
Draw a diagram of a UIKit class, showing instance variables for prototypical
button and text area objects and showing the creation methods that will return copies
of these objects.
Suppose that in the declarations of instance variables in UIKit , you initialize each object as
follows:
protected OzButton button = new OzButton();
protected OzTextArea textArea = new OzTextArea();
//...
At present, the various user interfaces differ in the font and the cursor you use for each
component. For full-screen components, you use the default cursor and the following font:
Font f = new Font("Dialog", Font.ITALIC, 18);
For handheld screen components you use the following cursor and font:
Cursor c = new Cursor(Cursor.HAND_CURSOR);
Font f = new Font("Dialog", Font.PLAIN, 8);
To create a factory for full-screen or handheld components, you create a UIKit object and set
the cursor and font of this object's instance variables. A convenient place to do this work is in
UIKit static methods that return instances of the appropriately tuned factories.
CHALLENGE 18.2
Write the code for UIKit.handheld() , a static method that returns a factory for
handheld display components.
Prototyping with Clones
To complete the factory design, you have to establish how the prototypical instance variables
in a UIKit object will copy themselves. You consider using clone() , a method that every
class inherits from Object . However, this method must be used with caution; it does not
provide foolproof copying of an object.
CHALLENGE 18.3
Consult the source code for Object.clone() and write down what this method
does.
Search WWH ::




Custom Search