Wednesday, November 28, 2007

Swingin' into '08

My first foray into the world of Java was back in 99-2000 when I was tasked with creating a rudimentary client/server app. The app was Swing based with simple UIs for the client and server parts of the app. I remember being struck at the time of how easy it was to create basic
UIs; much more so than the C++ Win 32 UIs I had written previously.

Since those days I've not really used Swing that much, my career since then has taken me more towards N-tier applications, generally with a web front end. In those eight years, I've used a number of web MVC frameworks and through the years have seen a great improvement in developer productivity and ease of development/integration as new frameworks have come along. In recent years, technologies such as AJAX have added a richer experience to the web client.

So, when I decided to take another look at my old friend Swing, I was excited to see what had happened in the intervening years. On initial inspection, not a whole lot seems to have changed. There have been good performance improvements, which is always worthwhile. One introduction in JSE6 (developed initially at SwingLabs) I've since used a lot is the SwingWorker class which helps offload long running tasks from the Event Dispatch Thread. There have also been tweaks to the look and feels (esp the Windows L&F).

However, I was surprised not to see more new features jumping out at me and begging to be tried. Perhaps there are more gems lurking which I haven't yet discovered, I hope so.

I think the main frustration in developing Swing apps is that although there is a wealth of supplied components; and it is relatively straightforward to create custom components; there's no centralised framework or patterns for laying out your application architecture.

There's also a large amount of boilerplate that has to be created for all apps. For example, how often have you written...

public void static main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MyAppFrame().setVisible(true);
}
};
}

... or something similar, just to make sure that the app is created on the EDT. I don't keep track (I'm not quite that geeky!) but it must be in the hundreds.

I'm therefore excited by JSR296 which should hopefully standardise the main structure of a Swing app and help development teams get up to speed more quickly as there should be a common understanding of how common functions are performed.

I'm also excited by JSR295 - Beans Binding which should simplify the process of binding the properties of GUI widgets to model properties removing yet more boilerplate for adding PropertyChangeListener instances.

Hopefully both of these will make it into JSE7 (Dolphin) but early versions are available on java.net.

I haven't had a chance to experiment with them yet but it's on the ToDo list.

One area I've been getting into since my return to client apps is animation and I've been experimenting with the Timing Framework developed by Chet Haase of Sun (available at http://timingframework.dev.java.net). It's fairly simple, only a handful of interfaces and classes. It's this simplicity that makes it a really nice framework to use. It's very easy to set up fairly sophisticated animations, quickly and easily with minimal coding required.

In the next few blogs I'll be running through some Timing Framework examples, showing how it can really simplify the creation of animations in Swing applications.

No comments: