While most of my posts so far dealt with JavaFX properties and bindings, today I want to write about another part of the JavaFX runtime I also work on: the animation API. In this article I will explain how to write custom animations in JavaFX and use this approach to create a class for sprite animations. (This will also be a good practice for one of my sessions at the conference 33rd Degree. I plan to write a game in JavaFX in just one hour. That’s going to be fun!) 🙂
The JavaFX runtime provides two possibilities to create read-only properties. You can either use a wrapper (e.g. ReadOnlyDoubleWrapper) or you can extend an abstract base class (e.g. ReadOnlyDoublePropertyBase). This article shows how these two approaches can be implemented.
Very often one has to create a number of of similar objects. Using JavaFX builders for this task instead of constructors has several advantages as we will see in this article.
In short, builders…
- are easier to read and understand
- avoid some “copy & paste”-bugs
- result in small, but simple code, if builders are reused
What a blast this year’s JavaOne was. From the three JavaOne conferences I have been to, for me personally this one was the most exciting one. It is one thing to sit in your office thinking that what you do might be real cool for developers. It is a completely different thing to actually get so much positive feedback.
I arrived on Saturday night, actually doing pretty good. I was able to sleep during the flight, which rarely happens. In the hotel I skyped with my boss and he asked me to pick up the tablets for the Tuesday keynote the next morning. Plans can change quickly: no sleeping in, no shopping presents for the kids… oh well, that is JavaOne.
On Sunday morning, I was able to sneak in the Java community leader brunch. I considered it a reward for getting up and taking care of the tablets. It was a very good meeting, where I met a lot of interesting people. I was even able to speak German with some of the attendees. It felt really weird to talk about JavaFX in my mother language, although I live in Prague for only four years now.
During the presentation a couple of the announcements for the next days were already presented, e.g. the JavaFX roadmap and the plan that we want to opensource JavaFX. The feedback was very positive and everybody agreed that overall Oracle is doing the right thing with JavaFX, only some details were seen differently.
The rest of the day I took off and finally did some shopping and met with colleagues who live in the area. In the evening, the traditional opening party of JavaOne took place in the Thirsty Bear (official title: Glassfish community party) which gave me more opportunities to practice my German. And I met a couple of people who left Oracle Czech a couple of month ago. It is funny, I travel across the globe and meet former colleagues from Prague.
Monday the first set of demos were presented. The waving and jumping Duke was already amazing, but when Jasper started to play Duke, I could not believe what I saw. Honestly, I did not know that this kind of stuff is already possible with JavaFX. After the session I spend some time reading tweets about JavaOne. Looks like I was not the only one, who was taken by surprise. The feedback was superb.
The rest of the day, I spend taking care of the tablets, charging them, making sure all of them have the latest version of Fossil Game installed and working on my sessions. In the evening we had the rehearsal for the keynote the next day. And there it happened. The game crashed on one of the devices. We have tested them thoroughly as you can imagine. I played the game up to level 10, it never crashed. Naturally we got “slightly” nervous. I took the devices back to the hotel and played Fossil Game again for more than half an hour – no crash.
Next morning was “our” keynote in which Nandini presented Fossil Game playing on Android, iPad, and a Windows tablet. Everything went well. What a relief! The ports are just prototypes and nobody in IT expects a prototype to be as stable as a released product, but still – you do not want your prototype to crash during a keynote!
The rest of JavaOne was just amazing. Whenever I talked to people and the topic came to JavaFX, people were just thrilled. Even people who usually do only J2EE stuff told me, they want to try JavaFX. Everybody was really impressed. It seemed, especially the sneak preview of our vision, enabling developers to use JavaFX for all platforms, ignited people’s imagination.
The rest of Tuesday I spent at two fun events, the JavaFX community lunch and a party in the evening. That was fun! It looks like every JUG leader now wants to do something about JavaFX in his or her JUG. The time between the events was filled with practicing my two sessions.
Wednesday morning was my first session about JavaFX properties and bindings. Attendance was actually quite good considering that the session started at 8:30 AM. It was the only day without a keynote and I can imagine most people used it to sleep in at least once. (Guess I would have.) The session went quite well. There was just one question for clarification. Either the presentation was well understandable or too simple.
There was one particular interesting question at the end of the talk: is it possible to bind across threads. Say you read a property from one thread, but its dependencies are usually updated from another thread. The idea was, that lazy evaluation could maybe decouple the two threads and require less synchronization. Right now, this will most likely cause synchronization issues and you have to take care of that manually. I like this question so much, because it presents us a usage of the binding API, we have not thought of so far, and I hope to hear more of such examples. May it be serious use case to solve issues in real applications or just crazy ideas to push the limits of what you can do with bindings.
Early afternoon John and I did the second session about animation with JavaFX. I think it went quite well – no questions for clarification. But the questions demonstrated a clear need for a tool to design complex animation. The animation API in JavaFX is flexible enough to satisfy a professional animator like John, but I think it is still very hard to come up with the right parameters like timing or the interpolators. Especially if it is not your daily job to define animation, you need to figure them out by trial-and-error. This is pretty cumbersome if you have to do it in code, a visual tool would speed up this trial-and-error phase tremendously. Unfortunately I doubt I have the time to write such a tool by myself. Maybe an open source project to split the effort would work. Let’s see, if I can find other interested developers.
Wednesday evening I was just exhausted. Sleeping only four hours every night and all the stress and excitement of the last couple of days finally got me. I went to bed early and do not even know what else went on that night. Guess everybody went to the concert anyway.
On Thursday nothing spectacular happened – at least to me. In the evening I flew back home, tired, excited, and curious what the future of JavaFX will bring.
This week I pushed the last two major changes in the JavaFX properties implementation, that were planned for this release. These changes may easily be overlooked, because the public API changes only slightly, but the possibilities they enable are way cool, I think, and I am very excited about them. Here is what you can expect in the upcoming beta drop.
JavaFX 2.0 properties build upon the popular Java Beans pattern and enhance them with some useful and extremely powerful features. In this article, I will take a closer look at the usage of JavaFX properties. It is the first in a series of articles, which will explain JavaFX properties in detail. Continue reading “JavaFX Properties”