O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required