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

492
|
Chapter 12, Miscellany
#98 Add Velocity for Dynamic HTML
HACK
out.writeObject(me.getComponent().getName( ));
out.writeObject(evt);
}
You also need to modify the
openReceiver( )
method’s loop to read a name
in before reading in an event. Once you have the name on the receiving side,
you can look up the proper component and associate that with the received
event.
With these changes in place, the program will work. Each event on the send-
ing instance side will be captured and sent over the network. On the receiv-
ing side, each event will be recreated and reposted. The two programs will
stay completely in sync; even rollover effects will happen simultaneously:
while(true ) {
String name = (String) in.readObject( );
AWTEvent evt = (AWTEvent) in.readObject( );
if(evt instanceof MouseEvent) {
MouseEvent me = (MouseEvent)evt;
MouseEvent me2 = new MouseEvent(
//me.getComponent( ),
(Component)component_map.get(name),
me.getID( ),
me.getWhen( ),
me.getModifiers( ),
me.getX( ),
me.getY( ),
me.getClickCount( ),
me.isPopupTrigger( ),
me.getButton( )
);
eq.postEvent(me2);
}
}
H A C K
#98
Add Velocity for Dynamic HTML Hack #98
Use the Velocity template engine to mimic server-side web technologies in
your Swing application.
Servlets, JSPs, and other server-side technologies help separate an applica-
tion’s model from its view and allow you to build flexible and dynamic web
applications. Of course, Swing applications have their own benefits, like fast
user interaction without the need for web server communication. It would
be cool to have the power of those server-side technologies right in your
Swing application, but without the overhead of a local web server. You can
actually mimic a lot of that functionality using a combination of Apache’s
Velocity template engine and a Swing HTML panel.

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