« Animating with Dynamic Timeline Values in JavaFX ...and a Scientific Fish Story from 1901 | Main | Leveraging JFXtras and Freebase with JavaFX to Create BandmatesFX »

June 24, 2009



JavaFX is catching up demand it seems.
I liked this review about javafx posted on TaranFX http://www.taranfx.com/blog/?p=1173

JavaFX is powerful! I never knew abt this!

James Weaver

JavaFX 1.2 has mixin inheritance. Quoting Weiqi Gao from excerpts of chapter 4 of our Pro JavaFX book:

"Understanding Mixin Classes

JavaFX Script supports a form of inheritance called mixin inheritance. A JavaFX Script class can optionally extend one JavaFX Script class and any number of JavaFX Script mixin classes...

A mixin class is a class whose primary purpose is to be extended by other classes and cannot be instantiated directly. Such a class is defined by using the mixin modifier before the class keyword. Like regular classes, mixin classes may contain instance variable and constant declarations, instance function definitions, init blocks, and postinit blocks. Here is an example:

mixin class Locatable {
var x: Number;
var y: Number;
function moveToOrigin() {
x = 0.0;
y = 0.0;
function setLocation(x: Number, y: Number) {
this.x = x;
this.y = y;

The mixin class Locatable will cause classes that extend it to have instance variables x and y and instance functions moveToOrigin()and setLocation().

Extending Classes

You extend JavaFX Script classes by including a super class and mixin list in a class definition. The super class and mixin list appear after the class name and consist of the extends keyword followed by a comma-separated list of class names. The list may contain an optional regular (non-mixin) class and any number of mixin classes. The regular class in the super class and mixin list is called a super class of the class. The mixin classes in the super class and mixin list are called parent mixins of the class. A class is called a subclass of its super class and a mixee of its parent mixins.

A class inherits its super class’s instance variables, instance constants, and instance functions to which the writer of the super class has allowed access. The smallest unit of access rights in JavaFX Script is the JavaFX Script source file. Therefore, if a subclass is in the same file as the super class, it inherits all of its instance variables and instance functions.

A mixee will inherit its parent mixin’s instance variables, instance constants, and instance functions to which the writer of the parent mixin has allowed access."

In this blog post example, the TaskController JavaFX class is extending one JavaFX class and one Java interface.

Hope that helps, John!
Jim Weaver

John O'Conner

Hi Jim,

The example you show above is surprising to me because of the multiple inheritance. I thought that multiple inheritance had been removed from JavaFX SDK 1.2?

The comments to this entry are closed.