Archives for August 2009
Flash for Swing Developers
It doesn't take one a long time to realize that Swing sometimes gets a bum rap. Developers had no idea how to handle the GUI thread and were prone to unknowingly block it. Add to that the fact that the default widget set LookAndFeel left much to be desired gave users the impression that Java Swing was kludgy, slow, and ugly.
Be that as it may, Swing has been around for over ten years now and not even the much ballyhooed introduction of JavaFX Script will be enough to kill it. That one core reason while Griffon doesn't try to do away with Swing. It says, "I know it will be around and there is a lot of legacy code in it, so let's use it in a more efficient way." I was happily surprised to find that there is a project for Flash that allows you to use Swing conventions and classes to create user interfaces in Flash. You don't even need a commercial application (Adobe Flash CS4 and the like) to get started.
You'll need to install the Flex SDK and add it to your classpath.
Grab AsWing libraries and extract the swc file into your working directory.
Create the following file as hello.as
package {
import org.aswing.*;
import org.aswing.geom.IntDimension;
import flash.display.*;
import flash.text.*;
public class hello extends Sprite {
public function hello() {
var frame:JFrame = new JFrame(this, "HelloWorld");
frame.setSize(new IntDimension(200,120));
var label:JLabel = new JLabel("Hello, World!");
frame.getContentPane().append(label);
addChild(frame);
frame.show();
}
}
}
From the command-line run: mxmlc -include-libraries=AsWingA3.swc hello.as
That should create a swf file in the same directory that, when run in the browser shows a frame with a label that says "Hello, World!". The above code should seem very familiar to Swing developers. The only key differences are the lines adding the frame and showing the frame.
In AsWing and in regular Flash, the top-level element is the Stage. addChild(frame) adds our top-level element for user interaction to that Stage.
frame.show() is deprecated in conventional Java but in Groovy, it acts as an alias to frame.setVisible(true). Of minor mention is the frame.getContentPane().append(label) line. Actionscript uses append instead of add that Swing prefers.
GTUG Campout and Trippy the travel assistant
I just got back from an very awesome GTUG Campout. The goal of the weekend was to code a functional Google app during the course of the weekend. On Friday, there were a couple of Wave tutorials but the balance of the weekend was all about hacking. Most of the teams chose to use Google Wave but there were a couple Android and general App Engine teams(Wave robots run in AppEngine).
My team and I created Trippy, a virtual travel assistant. We had airline and hotel information polling from Kayak and only after meticulously coding it and a handcoded XML to JSON parser (AppEngine doesn't like SAX or JDOM), we found that it horribly crashed on App Engine. Querying Yelp for points of interest in a given area was originally a wishlist feature but became the centerpiece of our demo.
How it works:
Trippy runs on the AppEngine and uses Google Wave to interact with users.
1. Trippy asks you what city you are interested in.
2. Trippy asks you activities you would like to do.
3. Trippy queries Yelp and returns the top three results for the keywords you entered including the name of the business, the phone number, address, and links to the business's review page on Yelp and a Google Map link.
To use Trippy:
Add him(trip-bot@appspot.com) to a wave and he'll start talking to you.

We didn't win any prizes but I'm proud of what we accomplished in the weekend. Sometimes the best way to learn is to be thrown into the deep end and told to swim...thought a swimming analogy was apropos given the name of the technology.
You can wave me (wave to me, not quite sure of the proper verb yet) at j@wavesandbox.com. Yup, just j. The source code to Trippy is out there but needs to be cleaned up.
I have to thank the GTUG organizers and volunteers are awesome and organized a great event.
Ten tips to help you enjoy GTUG Campouts
1. Be ambitious.
Hello World apps don't win cool swag.
2. Know thy limits.
Having an ambitious idea is great but if you can't execute it all, scale it down to what is doable in the weekend.
3. Have at least Plans A, B, and C.
In our project, what was orginally an afterthought add-on turned out to be the centerpiece of the demo.
4. If you're getting more than 6 hours of sleep each night, you're not doing it right.
45 hours is not nearly as much time as you think.
5. Go outside and walk around for a couple minutes ever so often.
After spinning in mud for an hour or so, a quick walk around the Googleplex can make the solution come to you. Not recommended at night when the doors lock behind you.
6. Check you veganism at the door.
All those preservatives in that junk food keeps you going. Sure, there'll be rabbit food during meals but otherwise embrace the junk food.
7. Arrive early on day one to scope out the locations of outlets.
A laptop doing a bunch of builds on battery power is an uphappy laptop.
8. Learn to sense when a Shirley or another photog is near.
That way you can force their "candid" photos to feature your good angles hiding the bags under your eyes and acne you got from eating so much junk food.
9. Be interesting enough to be drawn by David Newman(@dnsf).
I loved his drawing of me at OpenSocial weekend so much that I use it as my twitter photo.
10. Be flexible. / Get in where you fit in.
If I were doing a project in my free time I might do it using Groovy in some shape or fashion. During GTUG Campout, people gravitate towards their programming LCD. In my case, it's Java. If your pitched idea doesn't attract a team, join someone else's. If your idea overlaps another team's, consider joining forces or at the very least co-locating so that you can work through common problems. One of the other teams had an idea that was only slightly similar to my team's but if we had partnered, we could have been that more awesome.