Fun with JavaFX

Friday, December 4, 2009 by Matt Warman

I have recently discussed my application development with JavaFX. After using it for a while, I am generally impressed. I come from a Swing background, so desktop application development is not difficult. The concepts that you will most use are sequences, binding, and triggers. Sequences are arrays of objects, but JavaFX makes it easier to use. You can use an index of course, but the insert and delete keywords give more control. You can simply add to the end of the sequence, or insert or delete before or after any item in the sequence. The hardest thing to deal with is that there are no multi-level arrays in JavaFX.

Bind and triggers are an interesting way to dynamically update values on the screen. They seemed awkward to me first, but once you get the hang of it, they work well. You can use the bind keyword assign a variable or attribute a dynamic value. There are times though that the runtime won't update. Instead of Listeners, JavaFX uses the on replace keyword to change the value in runtime. Anything inside the brackets will fire when the value changes. Just update the bound variable in the on replace, and the runtime will update. It seems like you are creating the same value twice, but it is a better way to control runtime events, without a bunch of unused Listeners taking up space.

For most application development people, it is the ability to customize and extend controls that makes a language useful. One thing that I have been doing is creating custom groups. Each control, (Text, buttons, progress Bar, etc) are actually a node on a scene. You can use the Group container to combine the controls into a single class. The Group control is more than a container because application development people can add special attributes that affect the group. I have created a group of polygons that act as buttons. I can't use the ButtonGroup control, so I change the selected button and hover color inside the class by using attributes. The cool thing though, is that I don't create the mouse events in the class, but when I create the group. The mouse events interact with variable on my main class, so there isn't any coupling of my custom class to my main class. That means I can use my polygon buttons in any project I wish.

The are many different effects that you can apply to the controls, too many in fact. As most application development folk don't have a solid background in graphics, a solid guide on gradients, reflection, glowing and other effects, and animation would be great. I just don't know how to control some effects, and I am still learning how to blend effects to make things look cool. That tutorial or book would be my new best friend.

Comments for Fun with JavaFX

Leave a comment





Captcha