Contents
The JavaFX Script programming language is based on the Java Platform, and as such, requires JDK 5 or JDK 6 (6 is faster) to be installed on your system. If you have not done so already, download and install JDK 6 or JDK 5 now, before proceeding with this tutorial. When it comes to choosing a development environment, you have two broad categories of choices: use an Integrated Development Environment (IDE), or use a plain text editor. This choice is entirely a matter of personal taste, but the following summary might help you to make an informed decision. Generally speaking:
The JavaFX Script programming language is a compiled language, which means that any source code you write must first be converted into Java bytecode — the language of the Java Virtual Machine — before it can run on your system. This is true regardless of your development environment (be it command line or IDE). If you download and install NetBeans IDE for JavaFX or the JavaFX Plugin for Eclipse, the JavaFX compiler and runtime will be installed automatically. If you use a different development environment, the easiest way to obtain this software is to download the entire JavaFX SDK, which gives you the compiler, runtime, and a number of other tools. Another way is to simply download the latest compiler binary from the openjfx project website. The compiler itself is written in the Java programming language; installing the precompiled binary therefore becomes a matter of extracting the downloaded file and adding the Finally — if you want to live on the bleeding edge — you can join the OpenJFX Compiler Project, create your own copy of the compiler workspace, and build everything yourself from the compiler source files. (If you choose this approach, you will also need the 1.7.0 version of Apache Ant, plus a recent copy of Mercurial). If you have chosen the NetBeans IDE as your development environment, you can use the following instructions to create a project for your first script: a simple calculator. Step 1: Create a New Project Step 2: Choose a Project Name and Location Step 3: Add a Source File to the Project ![]() To add a source file to the project, choose Next, type "Calculator" as the file name, but leave the package selection empty. You will see a package warning at the bottom of the screen, but ignore this for now; throughout most of this tutorial, we will be placing code into the default package. Press the "Finish" button when done. Step 4: Paste Source Code, Compile, and Run the Application! In its place, paste in the contents of Calculator.fx. Certain keywords are now highlighted, showing that the editor now recognizes the syntax of the JavaFX Script programming language: Now look for these buttons along the top of the screen: This image has been scaled down to fit your screen. Click to enlarge.
Press the green button in the center to compile and run the application. If prompted, click OK to set Calculator as the project's main class. ![]() You should see output similar to the above. If so, then congratulations, your project works! If you will be working from the command line only, save
After compilation, you will find that the corresponding Java bytecode has been generated and placed into a file named You can now run the compiled class in the Java Virtual Machine with the following command:
The output is:
This application may be small, but it introduces you to some important programming language constructs (discussed in the next lesson). Learning these constructs is your first step towards mastering the JavaFX Script programming language.
| ||||||||||||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||