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

486
|
Chapter 12, Miscellany
#97 Mirror an Application
HACK
This hack performs a simple visualization: it creates translucent rectangles
with solid labels. The same technique could be used to create a much more
dynamic interface displaying more detailed information, such as button state,
component IDs, color settings, or any other artifact of Swing components.
One thing to notice here is that there are two or more labels visible at any
given time. This is because of the nesting of components—if the cursor is
over a text field and that text field is inside of a panel, then technically the
cursor is over both components, producing two labels. You could enhance
the
ComponentGlassPane to only draw one label by creative use of the
SwingUtilities.getDeepestComponentAt( ) method.
H A C K
#97
Mirror an Application Hack #97
With creative use of the AWT event log, you can bind two instances of an
application together over a socket, creating a mirroring effect.
One of the coolest—and severely underrated—features of Java is serializa-
tion. Because Java code runs entirely in a virtual machine, it’s possible to
send objects over the network to another program and have the objects still
functional when they get there. One day while perusing the AWT documen-
tation, I came across the
AWTEventListener. I wondered what interesting
thing you could do by capturing all of the events in a program. I could write
Figure 12-11. The normal window
Figure 12-12. The window with the glass pane showing

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