Thursday, March 27, 2008

Swing... why not?

Customer: "Can you create a desktop application quick please?"
Developer: "ohhhh I desktop application, sure... I will use MS Forms"
Customer: "But why not java? you told me you feel more comfortable with java"
Developer: "Shh... Swing is a pain in the ass, its hard to develop and slower than other technologies, I suggest..."

I've heard this several times, and this led me to start this post.

The common concerns about Swing are as follows (if you know other ones, just let me know and I will include them):
1. Swing is hard to develop.
2. Swing is slow
3. Swing is not suitable for Enterprise applications
4. The user feels more comfortable if the look and feel is similar to other desktop applications like MS Office, or calc... etc. And Swing looks very different, this might confuse most of the final Users.

Swing is hard to develop.

This can not be more far from true, the main problem with the Java Technology is the lack of tools, everytime Sun releases a new JDK or specification, the users need to suffer this problem, so they must implement everything from scratch using a plain text tool application, just because the IDEs does not have support to this new feature, but... Swing is not new!!!! Swing was released a long time ago, if you use Netbeans or Eclipse you will find that creating a Swing form (class) is just like .NET, even better. (btw, I'm a netbeans lover and they are working very hard to keep the IDE as much up to date as possible.)

Using Netbeans, you can drag and drop controls, use code templates, doble-click to create code for events, etc. It's very easy to create a swing form from scratch. You can create your own controls very easy and use them as normal controls with drag and drop. In a future post I will write an example of how to create an interface swing in 5 minutes... maybe less, and How to do the same using .NET, I think you would not notice the difference between these approaches (ok, well... maybe you will notice it just because the interface in java will be auto-resizable, and some other improvements).

Take a look of this: Swing fast sample

Swing is slow

This is another lack of knowledge, the JDK 5 and 6 have a lot of improvements in this way, and there's a lot of techniques to improve your Swing code in order to have a better user experience. I will do a post with some of this techniques.

Swing is not suitable for Enterprise applications

The Swing applications could also have a good connectivity with the EJBs, and everything will depends on how you solve this interaction from the design and architecture. If you use a SessionBean to execute a work and then uses a new Session bean to retrieve data then you will have some remoting problems, but you can create a Session Bean at server side to work as Model in the MVC pattern, in this way you will be able to use this model to execute the task and retrieve the required data in one or more calls from the server side, so, as I said... everything depends on your ability as architect, create JSPs and HTML application requires a lot of work, so I think Swing will reduce the amount of work to create Enterprise applications. In a 3rd post I will compare how to do the same from a Web Application and a Swing application, then I will compare which one best suits your needs.

One of the arguments used by some people about this point is because Swing is not flexible, so everytime you change a "page" you will need to redeploy the whole jar in the client machine. Ok, here is JavaFX to solve this, so there's no excuses now. :D


Look and Feel

If you say that the look and feel is a problem... think again, the pluggable look and feel of swing will let you change everything in an application, you could even put a look and feel just like Mac even if you work on windows.

Conclusion

Swing is a very powerful framework and you won't believe how easy is. This is a starter post in a series of articles about the uses of swing in a "serious" environments.

1 comment:

abbhhhiiiiiiiii said...

Hi X,

I would definetly agree to what you have expressed about Swing. Most of belifs are becuase of lack of knowledge and myth's. With Java 6 things have improved for Swings.

Most of the problem that people face with swing application is because of poor architecture designs.

Thanks
Abhilash Murali