Example 17.1.a: A window that can be closed

This example didn't get into the book. It modifies Example 17.1 to let the window be closed. It does this by subclassing Frame in a class called closableWindow. The closableWindow class overrides handleEvent to respond to Window.DESTROY events.

There are a number of ways this could be implemented. Here when we see a Window.DESTROY event, we just hide the window. You could instead call dispose() to completely destroy the window and its contents. You might also wish to implement a scheme where the Window.DESTROY event gets passed to the applet. There's no easy way to do this. You'd probably need to use a different constructor to pass a reference to the applet into the closableWindow class, then call the applet's postEvent or deliverEvent methods to move the evnt from the window's event queue to the applet's event queue.

The source code


Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home