Make Your Frame Dissolve #42
Chapter 6, Transparent and Animated Windows
|
219
HACK
H A C K
#42
Make Your Frame Dissolve Hack #42
Create animated frame dissolves using two screenshots and some clever
graphics code.
Dissolve is a term from old motion pictures where the director would switch
scenes by fading, or dissolving, from one image to another. Eventually direc-
tors came up with more interesting dissolves like the vertical wipe, the vene-
tian effect (little thin strips that look like venetian blinds), and the classic
fade to black. With a little bit of screenshot hackery, you can create similar
effects in Swing, allowing your program to fade away or do some other inter-
esting animation when the user quits.
AWT doesn’t support real transparent or shaped windows (though you can
fake it with a screenshot pasted into a window that fills the screen
[Hack #41].
Most dissolves involve applying some graphic effect to both the starting and
ending images, which in this case means the application window itself and
the rest of the user’s desktop under the window. With this in mind, the
basic plan is four steps:
1. Capture an image of the window.
2. Capture an image of the entire screen without the window.
3. Cover up the entire screen with a new window.
4. Show the dissolve animation.
Figure 6-3. Running the MP3 player

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.