Last week a friend of mine pointed me to a website and said "I'm sure you can't do this in Java...".
So it was about the following flash component called MagicButton, which looks like this...
But if you move the mouse over the button it shows it's magic, which is a nice gradient that fades in slowly if you leave the mousepointer over the button and it flashes if you move the mousepointer over the button and directly move it away from it.
So thats the challenge here...
Dynamic fade in a gradient if the mouse moves over the button and fade it out again if the mouse exits the button again plus the different behavior if you leave the mouse over the button or move it over the button.
Well fortunately there's a guy named Kirill Grouchnikov that created this really nice library called trident animation library. With the help of this library it was not really a problem anymore to create some similar button in Java.
When i was playing around with the button and the effect i thought it would be a good idea to add another effect to it, in the original flash version i missed the clicked/pressed state of the button and therefor i decided to add it in my example...
If you open the source (which is a NetBeans project) you will find two classes:
where the MButtonUI class is the ui delegate for the MButton class. In the MButtonUI you will find the painting of all the images that are needed to create the button (backgroundImage, contextImage, foregroundImage).
The painting of the effect is realized in the MButton itself and it uses the trident animation library to realize the animation effects.
That means you need to add the trident.jar file to your project if you would like to use the button.
The component allows you to set the hover effect color and also the clicked/pressed effect color.
To get a better impression of the animation you might want to try a little java webstart demo...
Enjoy coding and of course the upcoming weekend...