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)

About these ads

Trackbacks/Pingbacks

  1. Java desktop links of the week, April 16 | Jonathan Giles - April 16, 2012

    [...] Schindl has two blog posts up regarding JavaFX and Eclipse xtend being a perfect match, and a sensationally perfect [...]

  2. JavaFX links of the week, April 16 // JavaFX News, Demos and Insight // FX Experience - April 16, 2012

    [...] Schindl has two blog posts up regarding JavaFX and Eclipse xtend being a perfect match, and a sensationally perfect [...]

  3. JavaFX + xtend an ongoing love | Tomsondev Blog - May 29, 2012

    [...] 29, 2012 by Tom Schindl 0 Comments So I’ve already blogged (here and here) about the prefect match between JavaFX and [...]

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

Follow

Get every new post delivered to your Inbox.

Join 665 other followers

%d bloggers like this: