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.

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

Enterprising JavaFX @ #devoxx

Enterprising JavaFX @ #devoxx

In a couple hours Jasper and I will be presenting a talk titled “Enterprising JavaFX” at Devoxx. The main purpose of the talk is to describe how to use JavaFX for writing enterprise application content. Here’s a quick teaser screenshot of one of the apps we’re going to describe:

Jira Dashboard Application

Jira Dashboard Application

We’ll be writing some additional blog posts over the next few weeks describing various tips n’ tricks as to how we used web services in this app, how we wrote the custom list cells, and so forth.

Come see cool stuff at “Gaming JavaFX” @ #devoxx

Come see cool stuff at “Gaming JavaFX” @ #devoxx

bombdudeCome see a cool new game we have written on the current JavaFX release and learn how we wrote it. We’ll even post a link to play it online, though I might have to save that till the end otherwise all I will hear in the room are explosions coming from every laptop.

Gaming JavaFX
with Jasper Potts & Richard Bair
Firday 20th Nov  9:30am
at Devoxx

For those unlucky few who are not attending Devoxx this year, you will be missing many great things. We will post the game and some blogs about it over the next couple weeks and the recorded talk will be available early next year online as a video.

Hope to see you there 🙂

Function delegation

Just a quick post here. Found another example in Popup code that can be cleaned up and wanted to share. Here is the original code:

[jfx]
FX.deferAction(function() { doAutoHide(); });
[/jfx]

This line of code is going to use the FX.deferAction function which takes as a parameter a function with no arguments and no return. (FX.deferAction is essentially like SwingUtilities.invokeLater(Runnable)). However, since the doAutoHide() function already has this method signature, I can avoid creating the anonymous function and instead simply do:

[jfx]
FX.deferAction(doAutoHide);
[/jfx]

Much nicer.

Node Lookup

The Node class has a lookup function which is used for finding a node in the scenegraph based on an id. Every node has a String id, similar to HTML. In theory it should be unique within the scenegraph though in practice this isn’t necessarily the case.

This lookup function currently only operates over the “public” or “logical” scenegraph, not the physical one. For example, a Button is a Control which delegates its visuals to its Skin. The Skin has a sub-scenegraph. But since we typically want to encapsulate all that, we hide it from the programmer such that most things don’t find this part of the scenegraph. Seems like a reasonable thing to do (Swing went the other way and all the gory details were public which led to issues sometimes where people would dig around and rely on internal details — the horror! — and this made it incredibly difficult to fix bugs later in Swing).

CustomNode was our level of encapsulation. Any CustomNode’s children was explicitly not part of the public API. However, a number of people have complained, likely because they aren’t using CustomNode for encapsulation but rather for modularization of their source code (ie: break a huge file into several files where each piece extended from CustomNode).

So it seems like this partitioning of “logical” and “physical” scenegraphs is quite confusing at times. So the question is, should the lookup function operate on the physical scenegraph? Vote!

[poll id=”2″]

Looping in FX

I was doing a bit of work today reviewing the Popup class we’re working on for the next release of JavaFX. I showed Jasper some code snippets and he pointed out that I should write a quick blog on it because it shows a nice progression of how to do looping in JavaFX. (more…)

That Infernal Scene Graph Warning Message

Stuart Marks (one of the UI Controls “heavies”) has a great write-up on that “Infernal Scene Graph Warning Message”. You know, the one that showed up in JavaFX 1.2 in seemingly innocuous situations such as the following:

[jfx]
var g = bind Group {
translateX: someX
content: node
}
[/jfx]

In this code, whenever “someX” changes, a new Group is created and the node is mysteriously moved from this Group to the new one, and in the process the “infernal scenegraph warning message” is printed. Stuart goes into a lot of great history and detail to give context to the problem, but here is probably the money-quote as to why the warning message was useful:

When we added the enforcement code, we were surprised that it uncovered a few bugs and quite a number of questionable coding practices in our code, both in our runtime library and in our samples. In one case a node from the scene graph was also being used as a clip. This was illegal and didn’t actually work, but nobody had noticed up to that point. As for questionable coding practices, the enforcement turned up quite a number of cases where a scene graph was being constructed with some initial structure, and some code later on would rearrange the nodes into a different structure for no good reason. This caused the scene graph machinery to do a lot of extra work. The fix was to rewrite the code to create the scene graph in the desired structure, avoiding the rearranging and any error messages that the old code had caused.

Go visit his blog to get more information, I’m waiting for the second installment which I anticipate will go into all the nitty gritty details. Its kind of a cliff hanger because he doesn’t tell you what the final unanimous decision was regarding the warning message. Codify it as an error? Remove it? Something else?

Win $2000 in RIA Exemplar Challenge

Win $2000 in RIA Exemplar Challenge

Create an application in JavaFX that exemplifies the appearance and behavior of a next-generation enterprise RIA (rich internet application)

See the official announcement for more details on the rules etc. Announcing the JavaFXpert RIA Exemplar Challenge

Announcing the JavaFXpert RIA Exemplar Challenge

I will be judging the entries for their visual design with the help of fellow graphics judge Romain Guy. To help all the designers entering here are a couple of the original designs for the Caspian theme along with links to the photoshop files they were created with. This way you can see the how all the all the controls visuals are contracted using vector shapes and layer effects.

Download Controls.PSD.ZIP

Download Controls Mockup.PSD.ZIP

I also thought maybe some links to sites with good articles on design might be helpful. Most of these are associated with Web Design rather than Application User Interface Design but there is a large amount of cross over and I have not found any good sites on Application User Interface myself.

Here are a few links for inspiration: