FX Experience Has Gone Read-Only

I've been maintaining FX Experience for a really long time now, and I love hearing from people who enjoy my weekly links roundup. One thing I've noticed recently is that maintaining two sites (FX Experience and JonathanGiles.net) takes more time than ideal, and splits the audience up. Therefore, FX Experience will become read-only for new blog posts, but weekly posts will continue to be published on JonathanGiles.net. If you follow @FXExperience on Twitter, I suggest you also follow @JonathanGiles. This is not the end - just a consolidation of my online presence to make my life a little easier!

tl;dr: Follow me on Twitter and check for the latest news on JonathanGiles.net.

Silicon Valley JavaFX JUG

I had the honor to be the first official speaker at the first JavaFX user group meeting (of which I am aware!). The Silicon Valley JavaFX JUG, organized by Stephen Chin (one of the authors of Pro JavaFX, which is an excellent book), met this past Wednesday. Google hosted the event and supplied the evening’s pizza, for which I am personally very grateful!

PDF Version

Stephen had setup a streaming feed so people not in the area could follow along, which I thought was really cool. Its always fun to present about JavaFX as it is something I’m passionately interested in. Yes, working on JavaFX is my day job, but if I didn’t really love it and believe in it I wouldn’t be doing it. The thing that energizes me is knowing both what it is that we have built, and what we are building. It is really a fantastic platform. Its a joy to use when building applications and getting better all the time.

That Infernal Scenegraph Warning Message: Part Deux

Stuart Marks has written up part II of the three-part series on the scenegraph warning message that you have seen in JavaFX1.2. I covered and linked to the first version previously. It really is a terrific read, and details some of the subtle semantics of bind. Stuart always does such an excellent job describing these subtle issues.

In my earlier post on this topic I hinted that we had found a resolution to the issue surrounding the warning message, I hinted further in some of my replies to comments, and I even left it as sort of a cliffhanger as to what the resolution was. So, here’s the resolution.

We’ve decided that when a node is added to a group, that node is automatically removed from the group that previously owned it, if any. (Let’s call this the “auto-remove” feature.) We’ve also decided to turn off the warning message by default, but to have it be enabled optionally, possibly via a system property, for debugging purposes. Finally, we’ve relaxed the enforcement of some scene graph invariants in cases where the group’s content sequence is bound.

During the development of our current release, we kept running into this issue. A couple of us wrote code that we thought was reasonable, yet it surprised us when the warning message came out! We had a few hallway conversations from time to time, but a clear-cut answer never emerged. Finally, we realized that we had to get the interested parties in a room and have a knock-down, drag-out meeting to resolve the issue. And so on October 7, 2009, Amy Fowler, Kevin Rushforth, Richard Bair, and I got into a conference room to decide the issue. Three hours later — with no breaks! — we had decided. Actually, it was a great meeting, without a lot of conflict. There were just a lot of issues to cover. Each of us came into the meeting with our initial opinions, but the issues were so close that I think each one of us switched sides at least once during the meeting.

Writing a Java-based Task

In a post from earlier this year I explored the concept of background tasks in JavaFX. If you haven’t yet, you might want to review that article before reading on. For the impatient: JavaFX is currently a single threaded programming language. All code you write in JavaFX occurs on the same thread. Since you don’t want to write an unresponsive application, you need to write long-lived operations on a background thread. The Task API provides a single consistent abstraction which all background operations in JavaFX are based on. This means whether you are computing fibonacci sequences, breaking down protein chains, writing to a database or reading data from disk there is a single consistent programming model and API that your GUI communicates with. And we think this is a pretty good idea. (more…)

Language Lesson No. 1: Object Creation

We’re intending to write a number of different smaller blog entries focused on describing various features and usages of JavaFX Script. I was asked several times by people this week at Devoxx, why choose JavaFX instead of HTML, Flex, or something else? The two real strong advantages of JavaFX are that 1) you have access to a wealth of Java APIs if you need it, and 2) Developing in JavaFX Script is highly productive.

It is this second point that I hope becomes clear and I hope to convey with this series of Language Lessons. Many times Jasper and I have been holed up writing demos with JavaFX and it is not uncommon for us to just pipe up every so often with “this is just so cool” or “javafx makes some things reaaaaally nice”. I know this sounds like the cheerleader squad coming from the guys who have been part of building this product. Call it pride in craftsmanship. Its honestly how we feel, and hope to convey this to you as we go along.

So with that, here’s the first Language Lesson: Object Creation.

There are actually two different syntaxes for creating objects in JavaFX. One should be used for creating Java objects, and the other for creating JavaFX objects. If you are going to create a Java Object, you will most often want to use the “new” keyword — exactly like you do in Java. You can either use the default no-arg constructor (if the class you are creating has one) or one of the other constructors. For those not familiar with Java, it looks like this:

[jfx]
def obj = new StringBuffer("Hello World");
[/jfx]

The second syntax is what we call the Object Literal syntax, and looks more like object creation in JavaScript than in Java. JavaFX Script supports a different concept for object creation and initialization from Java. In the Java world, you have to call one of a fixed set of (generally) explicitly defined “constructors”, which are essentially special functions that create an object. Each constructor has certain parameters, just like functions.

This usually led to object creation & initialization code that looked like this:

JButton button = new JButton();
button.setText("Cancel");

In JavaFX Script, there are no explicit constructors. Instead, you say what object you want to create and what initial values to give to each variable. If you don’t define an initial value for a variable, then the class will use its own initial value. For example, you might do this in JavaFX Script:

[jfx]
Button {
text: "Cancel"
}
[/jfx]

There are some subtle differences between these two cases for a library author (like me), but it works really exactly the same as far as users of the library (like you) are concerned. The difference is that the traditional Java approach is very procedural (do this, then do that) whereas the FX way is declarative. In such simple examples as this it makes no difference, but as we will soon see as the Language Lessons continue, this declarative style lends itself to some very cool possibilities.

Until next time, have fun coding.

Games, Physics, JavaFX #devoxx

Games, Physics, JavaFX #devoxx

We just finished our talk here at Devoxx called “Gaming JavaFX”. The talk was scheduled for Friday morning and we wanted to do something really fun and a bit lighthearted, but also really practical. Earlier this week James Gosling had a talk about the Java Store, and we wanted to provide some momentum to the idea that you can write really fun and interesting games in JavaFX and then load these up into the store.

Jasper posted a preview teaser earlier in the week of our Dude with a bomb. You’ll appreciate watching the talk at Parley’s when they have it posted (or you can pay Parley’s a few quid and see the talk even earlier).

Dueling Sketch

The game we wrote is called “Dueling Dudes”. Its a non-scrolling side shooter, not unlike some other popular games like Scorched Earth or iShoot. Except we decided to replace the tanks and earth with dudes and boxes. We placed it in a warehouse and gave each box & barrel physical properties, and gave our dudes weapons and the ability to bash the terrain around. It was tremendous fun. I once read that every programmer should write a game at least once a year just for fun and to keep that youthful exuberance. I couldn’t agree more.

Technically it was a very pleasant and fun thing to work on as well. Integrating the physics engine was not very much work, and using a scenegraph to model things was very natural. We drove things mostly from the engine and a few well placed binds and a single Timeline which drove the world. Jasper pretty well wrote the whole thing over 3 days. Here was our secret equation for success:

Equation For Success

We’ve hosted the game here at FXExperience, hope you enjoy playing it (and if you have troubles on your machine configuration we’d like to know that too!).

DuelingDudes

Click To Play