In the first post of this weblog, I showed you how to use JavaFXPad to play around with interpreted JavaFX Script. Now I'd like to show you how to do the same with compiled JavaFX Script. In order to get this version of JavaFXPad, you'll need to download and build the compiler, but I think that it is totally worth it. Hopefully this compiled version of JavaFXPad will be made available via Java Web Start in the near future.
After you've downloaded and built the compiler, navigate to the sandbox/fxpad directory and execute the appropriate run_compiler script. When JavaFXPad starts, choose the Run>ClassPath menu item and select the following three JAR files:
- dist/lib/javafxrt.jar
- dist/lib/javafxc.jar
- dist/lib/scenegraph.jar
Then deselect the Run>RunAutomatically menu item so that it doesn't try to recompile and run the program until you're ready. Note: The current behavior of JavaFXPad seems to be to virtually ignore this setting, so I typically cut and paste chunks of code into JavaFXPad. You can also use the File>Open menu item to load your program.
If your program has a Frame and you want it to appear in a separate window rather than drawing it directly on the top area of JavaFXPad, then assign the Frame to a variable as shown here:
import javafx.ui.*;
var frame =
Frame {
background: Color.WHITE
width: 300
height: 200
visible: true
title: "Separate Window"
content:
FlowPanel {
content: [
Button {
text: "Press me"
}
]
}
}
Here's a screenshot of JavaFXPad after pasting the program shown above into it:
Have fun playing around with compiled JavaFX Script code!
Regards,
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
eBook (PDF) download available at the book's Apress site
Hi Jim
Thanks, nice tip. A couple of comments
1) It seems there is some dependency on Java 6--at least, I couldn't launch FXPad with the compiler on OS X with Java 5--was reporting missing classes (appeared to be related to the Scripting API in Java 6). Works on Ubuntu, tho.
2) Opening a new frame--careful! With the bug in "run automatically" any change in the script will pop up a new frame.
Regards
Patrick
Posted by: Patrick Wright | December 08, 2007 at 12:29 PM