What's cool in AWT on Java SE 6

Having worked on the testing side of the AWT for the Java SE 6 release, I am really tempted to write about some of the cool AWT features that I came across in Java SE 6. We already have a feature-rich Swing and a solid AWT as part of the Java SE for writing some cool GUI and what AWT offers on Mustang would really be an extra icing on the cake.

We come across so many different applications in our day-to-day life and each of them is unique in it's own way. Being a test engineer for Java, I always tend to compare each of these applications with our own Java apps to see how are we doing?!! (After all, that is part of my job isn't it?!). There are times where I have wondered how cool would it be to offer some of the cool features that some native apps provide, as part of the Java SE. Say for example - We use different types of Instant Messangers such as Yahoo, ICQ etc. When you minimize the main window, you don't see it on the taskbar. Instead it appears on the system tray. Well, we could just use that space for keeping something else right?

When you open a native application such as StarOffice or Acrobat Reader it often tells you in some way at start-up how long it would take to oad the application (a progress bar?). Sometimes, apps may show a jazzy, funny splash screens with lots of animations. Likewise, we do come across many Hi-Fi games and we sometimes get addicted to it. But it would be interesting to see what would it take to implement them in Java ?!!.

AWT has answered some of these questions by offering a SystemTray and a SplashScreen feature on Java SE 6. Now it is possible for any Java App to go live on the system tray and free-up some space on the taskbar (with very little effort, of course). So if your app takes little longer time for loading and you are afraid that you may not be able to retain the attention of the user till then (whose impatience brings up 10 other applications on the screen otherwise) or if you just want to engage your user with a nice animated comedy until your app kicks in, Here is the solution - AWT Splash Screens !!

Having said that, I can not overcome the temptation of telling what these APIs offer to the Java community.
Let's first see what a Tray Icon is -

A tray icon is a small icon represented by an image that can be added to the SystemTray on the desktop. A system tray on Microsoft Windows is often referred to as the "Taskbar Status Area", on Gnome it is referred to as the "Notification Area" and on KDE it is referred to as the "System Tray". The system tray is shared by all applications running on the desktop. A tray icon may optionally include a popup menu and a tooltip.

System Tray screenshot
System Tray on Windows XP

So using Java SE 6, now you can add a Java tray icon to the system tray with an optional Tooltip / popup menu. You don't have to keep your app on the taskbar anymore (This feature is not entirely new to Java Community since it was there on JDIC before).

What does Java Tray Icon offer you?
- Add a popup menu and exercise the necessary actions without bringing up the application on the screen.
- Display a tooltip on mouse rollover
- Display a balloon message whenever necessary (could typically be error, info, warning or general)
- Have animation on the tray icon by using an animated GIF image
- Use GIF, JPEG and PNG images of varying transparency and change the images whenever you wish
- Track Mouse Events, Action Events triggered by the tray icon, balloon message
- Get notified when tray icon gets removed from the notification area
- Add as many icons as you would require

Message on a java tray icon
Java Icon displaying a balloon message

Popup Menu on a Java Tray Icon
Java Icon with a Popup Menu

The java icons will be removed automatically when the JVM exits and you don't have to worry about removing them yourself.

Wait a moment !! If you are an applet developer, remember that the tray icon will require 'accessSystemTray' AWT Permission in order to be used from within the applet. Before all that, make sure SystemTray is supported on your platform by calling SystemTray.isSupported.

Refer  java.awt.SystemTray , java.awt.TrayIcon for more details. Also don't forget to look at the technical article on SystemTray.

So download the latest Mustang bundle and Get your java apps live on the system tray.

Coming to Splash Screens, now AWT facilitates showing a 'creative' and a customizable splash screen for a Java application at the start-up, with a command line switch.
For Example:
java -splash:<img file> abc

where 'abc' is the name of the class you want to launch. The splash screen would stay on the screen until your application opens up a window or you close it by yourself from within the application.

(If your application is a packaged jar file, you could use the 'SplashScreen-Image' in the manifest file to make use of the splash screen feature)
AWT gives you control to the Splash Screen through java.awt.SplashScreen class.

Wondering what else could be exciting in a Splash Screen? - Here you go!!
- Supports GIF, JPG PNG Images
- Supports Translucency and Animation
- Get a handle to the splash screen and get it's location and size.
- Draw anything on top of the image (a progress bar?) through the Graphics2D object
- Close the splash screen through the application
- Change the image displayed in the splash screen to something cool

Remember that you can only control the splash screen already specified, through the SplashScreen API and you can not create a new one. Please refer the Splash Screen technical article for more information.

So get some cool animations right on the splash screens for your Java App with extremely little effort and make it more interesting for the end user.

More to come .....


thanks for the updates...

Posted by Ashutosh on October 13, 2007 at 02:00 AM IST #

Is there anyway to create notification window like MSN's user online window in Java SE6?

Posted by Adnan Siddiqi on July 04, 2008 at 05:46 AM IST #

It's simple Math

Posted by Taher on October 28, 2008 at 07:37 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed



« July 2016