JavaFX + xtend a perfect match


So after having used xtend for a while as a pure templating language I thought it’s time to explore how it can be used when programming JavaFX.

JavaFX 2.x API is already designed to be used for lambda expression support which will come with Java 8 so e.g. all event handlers accept a SAM type as their sole parameter. xtend already provides lambda expressions and so one can write less code.

Java:

b.setOnAction(new EventHandler<ActionEvent>() {
  public void handle(ActionEvent arg0) {
    // Some expression goes here
  }
});

xtend:

b.setOnAction [
  // Some expression goes here
]

// or if you have an equal-sign fetish:-)
b.onAction = [
  // Some expression goes here
]

The same is true for bean properties which look like this:

Java:

Button b = new Button();
b.setText("Say hello");
String v = b.getText();

xtend:

val b = new Button();
b.text = "Say hello"
val v = b.text;

The complete source code looks like this:

I’ve recorded a small video showing how to create a JavaFX project which uses xtend to the final exported application. The video highlights the amazing new feature the itemis guys added to their latest milestones when running your xtend code in debug mode – good job.

I’ll try to explore more xtend features like using the builder support but I need to first understand how this really works (too bad I missed their EclipseCon tutorial)

3 thoughts on “JavaFX + xtend a perfect match

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s