A Clock using NativeSkin
Skin Look And Feel gives the developer access to native functions such as irregular windows, transparency, always on top feature.
The clock we are going to create will use all the features of NativeSkin.
Having a rounded clock is one of the goal, here is the picture we will use for the background of the clock:
The image is a transparent GIF. Setting the window shape to be a circle is pretty easy using NativeSkin and ImageRegion. First you need to load your image then to apply the region to the window. Here is the relevant code from Clock.java:
// create an ImageRegion from the background image // so we can use a rounded clock ImageRegion region = new ImageRegion(back); NativeSkin.getInstance().setWindowRegion(window, region, true);
The clock will need to be always visible and on top of all other windows:
// A clock should always be on top of other windows NativeSkin.getInstance().setAlwaysOnTop(window, true);
Finally if the clock covers a large area you may want it to be transparent so what is under the clock is still visible. The transparency can be set from 0 to 255, where 0 means no transparency (opaque) and 255 totally transparent. The transparency is currently supported only on Windows 2000.
// but transparent so you can see through NativeSkin.getInstance().setWindowTransparency(window, 127);
That's it for the NativeSkin part of the clock, the rest is the clock design itself. We will not go deeper.
java -cp nativeskin.jar;. Clock clock.gif
Here is the result of our clock running on top of Netbeans:
If you encounter problems with the transparency not being applied (specially with JDK1.4), try to disable DirectDraw by passing -Dsun.java2d.noddraw=true to the virtual machine:
java -Dsun.java2d.noddraw=true -cp nativeskin.jar;. Clock clock.gif
You can view the online demo here if your browser is JavaWebStart-enabled. The demo will open a clock in the top left corner of your screen. You can move the clock by clicking in it and moving your mouse. To change the transparency, use the popup menu (right click on the clock). To close the clock, use the Exit menu item.