java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Window
|
+----java.awt.Frame
|
+----AppFrame
This class defines a graphics Frame, initializes the Applet context and specifies handling for the WINDOW_DESTROY exit event, for a class Room object or for an array of Room objects. The class Room implements the graphics window of Feldman's "Spider graphics" programs developed in the textbook "Ada 95".
The AppFrame object in creating a Room, allows proper bootstrapping of the Graphics object (context). The objects of this class inherit from Frame (they can be drawn into, they can be added into a container, resized, shown, and so on). When creating a new Frame object, the AppFrame() constructor expects an Applet object as its second parameter, and calls the Applet.init() method as its last order of business. This round-about initialization is necessary for resolving a Catch-22 situation, as follows:
The Graphics context of a drawable (surface) is unavailable until the drawable is installed in its container. Prior to this, getGraphics() would return null, so it is useless to call it when the drawable is instantiated (with "new ..."). By making the drawable an Applet, it can be instantiated without calling getGraphics() in the constructor. Instead, the init() method of the Applet object (overridden in the subclass) is used to call getGraphics(). The AppFrame container object can thus install the drawable component, Applet, into its Frame first, using the add(), resize() and show() methods of Frame. Thereafter the AppFrame() constructor calls the Applet init() method. The init() method is overridden in the Room subclass in a manner to call getGraphics() and assign the returned value to the "Graphics mySurface" field of Room:
mySurface = getGraphics();
Other drawable classes could be substituted instead of Applet: for example Room could subclass Canvas. Canvas does not have an "init()" method, but a non-overriding init() method could be defined in Room nonetheless; or a different method name could be used. In this case the type of the second parameter of the AppFrame constructor would have to be the subclass name Room: the parent class Canvas could not be used since it does not have an init() method.
public AppFrame(String title,
Applet anyApplet,
int wide,
int high)
public AppFrame(String title,
Applet appletArray[],
int wide,
int high)
public boolean handleEvent(Event anyEvent)