Java Reference
In-Depth Information
How to do it...
Open your favorite text/code editor and type the following code. The full code is available from
ch01/source-code/src/hello/HelloJavaFX.fx.
package hello;
import javafx.stage.Stage;
import javafx.scene.Scene
import javafx.scene.text.Text;
import javafx.scene.text.Font;
Stage {
title: "
Hello JavaFX
"
width: 250
height: 80
scene: Scene {
content: [
Text {
font : Font {size : 16}
x: 10
y: 30
content: "
Hello World!
"
}
]
}
}
Save the file at location
hello/Main.fx
.
To compile the file, invoke the JavaFX compiler from the command line from a directory up from
the where the file is stored (for this example, it would be executed from the
src
directory):
javafxc hello/Main.fx
If your compilation command works properly, you will not get any messages back from the
compiler. You will, however, see the file
HelloJavaFX.class
created by the compiler in the
hello
directory.
If, however, you get a "
file not found
" error during compilation, ensure that you have
properly specified the path to the
HelloJavaFX.fx
ile.
How it works...
The javafxc compiler works in similar ways as your regular Java compiler. It parses and
compiles the JavaFX script into Java byte code with the
.class
extension.




