
202
|
Chapter 5, Windows, Dialogs, and Frames
#39 Spin Open a Detail Pane
HACK
to ever have a reference to the dialog. With DialogEarthquakeCenter, how-
ever, you need that reference. So, instead, you provide the usual
JOptionPane
values (message, message type, user options, etc.) to the
JOptionPane
con-
structor, and then derive a dialog with
createDialog( )
. Don’t worry—you
still end up with the same option dialog.
Next, you create a
DialogEarthquakeCenter
from that dialog. Then you can
return to the dialog,
pack( ) it, and make it visible. One hazard of working
with the
JOptionPane dialog is that it is modal, meaning it will block the
AWT event-dispatch thread when shown; thus, it won’t shake because
DialogEarthquakeCenter won’t get any animation callbacks from Timer. To
get around this, I just made the dialog non-modal—after all, the user proba-
bly isn’t going to be able to click it when it’s moving. Another option might
be for the
DialogEarthquakeCenter constructor to remember if its dialog is
modal, and to reset this state in
stopShake( ).
Unfortunately, there’s not a great way to show the effect of this animation in
book form. The best I can suggest is that you compile and run the hack for
yourself. While you’re at it, change some of the constant values to see the
effect of longer or shorter shake cycles, distances, and durations.
H A C K
#39
Spin Open a Detail Pane Hack #39
You don’t want to bombard the ...