Design Patterns Java™ Workbook

(Michael S) #1
Appendix B. Solutions

Prototype (Chapter 18)..............................................................................................................................


SOLUTION 18.1....................................................................................................................................


Figure B.23 shows a solution. Note that this class is concrete. You will soon establish
instances of this class as complete user interface factories.


Figure B.23. A UIKit object is a wellspring of GUI components that have a consistent
look.

SOLUTION 18.2....................................................................................................................................


Here is an example solution:


public static UIKit handheld()
{
UIKit k = new UIKit();
Font f = new Font("Dialog", Font.PLAIN, 8);
k.button.setFont(f);
k.textArea.setFont(f);
Cursor c = new Cursor(Cursor.HAND_CURSOR);
k.textArea.setCursor(c);
return k;
}


The object k is a kit that can create components suitable for a handheld display.


SOLUTION 18.3....................................................................................................................................


The comment for Object.clone() in JDK 1.2.2 says that this method "creates a new
instance of the class of this object and initializes all its fields with exactly the contents of the
corresponding fields of this object, as if by assignment; the contents of the fields are not
themselves cloned. Thus, this method performs a 'shallow copy' of this object, not a 'deep

Free download pdf