Explore JavaFX Script alongside SDN staff writer and developer John O'Conner, who candidly records his experiences with learning Sun's latest software innovation. This Learning Curve Journal series begins with an introduction to the technology and how to get started using it. JavaFX Script was announced at the 2007 JavaOne Conference in May. The technology is still very new, but Sun Microsystems and the community are making dramatic progress each week. So it is a good time to get involved with the language. It has progressed enough that you can actually download and use it. Several beautiful demo applications exist, showing the possibilities of this language. JavaFX Script is a new scripting language that developers can use to create dynamic graphical content. The language provides libraries to help you use the Swing user interface toolkit and Java 2D APIs conveniently. It doesn't replace either Swing or Java 2D; the goal is to make those APIs more accessible to rich content developers. The language provides both procedural and declarative syntax. You can declaratively create a rich user interface, and then you can add event-handling routines and operations. However, most of us have to start more modestly, and that's the purpose of this article. Its goal is to show you how to get started with JavaFX Script. First, you'll need four things:
Setting Up the Java Platform
As a developer, you no doubt have a Java SE Development Kit (JDK) on your system. However, if you haven't updated your system in a while, make sure you have either Java SE 5 or Java SE 6. If you use Solaris, Windows, or Linux, you can download the latest JDK from the Java SE Downloads page of the Sun Developer Network. If you use Mac OS X, you can get Apple's latest release of the Java platform development kit directly from their Java section of the Apple Developer Connection. Going to the Source
When you experiment with a new environment or language, you're going to hit dead-ends and difficult places. That's part of the deal we all make when we adopt leading-edge technology. However, to smooth the learning curve, good documentation and examples are absolutely critical. Along with the JavaFX Technology hub of the Sun Developer Network, the Project OpenJFX web site provides the latest documentation and demo resources you need to get accurate information. Inevitably, there are holes in the documentation, but people are working hard on filling those holes. So bookmark these two sites in your browser, and refer to them early and often:
Some of you will want to start programming immediately, barely reading a word of the language specification. Others of you will read everything you can before actually using JavaFX Script. Even if you're the type that dives in right away, you have to start with some sort of language specification or tutorial. Before you can scribble out the prototypical "Hello, world," example, you need to know some basic language syntax. These documents are the best places to start: Using JavaFXPad
JavaFXPad is a Java Web Start application that provides a split-pane environment, with a live canvas window above and a simple editor below. As you type script code into the editor, the canvas window shows the interpreted results. It's the fastest, easiest way to experiment with the language when you're just starting out. The user interface shows the immediate results of your code. You're probably not going to use this tool for all your development needs, but it does its job well, which is to provide a quick and easy way to tinker with the scripting language. After you've read at least some of the language specification document, run the JavaFXPad demo. If you've installed the JDK correctly, you should be able to do this from your browser; just click the link. Alternatively, you can always run the command line utility
If you've successfully launched the application, you should see a window like this:
The JavaFXPad editor provides basic formatting and code completion. Programmers new to JavaFX Script -- that's all of us -- aren't always sure what the language syntax expects, but code completion helps. Pressing the Once you have successfully run JavaFXPad, you can begin experimenting with the language. After clearing the initial demo code, begin your own program. Of course, who can resist starting with "Hello, world!" Type the following into the empty editor window:
You'll see the output just above the editor:
Not impressed? OK, although I'm really just trying to show you how to get set up, I'll stry something a little more interesting. The JavaFX environment implements all of the Swing UI components, so you don't have to limit yourself to a label. You can use other widgets too, like buttons or dialogues. Here's an example that introduces an event handler on a button. Having seen the
After typing this into JavaFXPad and pressing the button, you'll see something like this:
JavaFXPad also has "Open" and "Save" file operations, so you don't have to start from a clean slate every time you use the tool. Although JavaFXPad may not be your long-term development editor, it is convenient and simple, perfect to help you get started. Once you feel comfortable with this tool, you can always use the same files in a different editor or even an integrated development environment (IDE). Graduating to an IDE
When you do decide to tackle JavaFX Script from your IDE, you'll find plugins for at least two popular tools: NetBeans and Eclipse. The plugins enhance editor- and project-support to include JavaFX Script files. The plugins provide the core libraries for the script engine and its libraries as well. The plugin download instructions on the Project OpenJFX site work well. Use the following links:
The instructions work for the updated NetBeans IDE 5.5.1 too. I did deviate slightly from the Project OpenJFX instructions; I created a new "JavaFX Script" update center in NetBeans instead of overwriting the existing NetBeans Update Center Beta node. After creating a new update center node, I followed the rest of the instructions exactly. Once you have the update center configured correctly, getting the plugins doesn't take long. Select the Update Center you configured in the instructions, and the Update Center Wizard should eventually present you with the following modules to download:
The wizard will look like this after it finds the plugins at the Update Center:
Once NetBeans downloads the modules, the wizard will prompt you to install them. Select the check boxes beside the module names and continue the installation.
Once you have installed the plugins, you can edit and run script files in your IDE. You have two ways to launch scripts from the IDE: use the
Summary
When investigating new technology, starting off correctly is important. Make sure you get started with the right information and tools. The best way to do that is to follow this four-step process
Part 2 of this series to follow. DISCLAIMER |
Learning Curve Journals
- Part 2: Declarative User Interfaces - Part 3: JavaFX Script Functions and Operations | |||||||||||||||||||||
|
| ||||||||||||