Tag Archive 'javaFX'


Aug 05 2008

Learning Curve Journal, Part 1: Exploring JavaFX Script(3)

Published by mac0002 under technology

Creating a JavaFX Application

After you’ve read at least some of the language reference document, it’s time to build a simple JavaFX application. Although you can build and run a JavaFX application manually from a command line, let’s do it using NetBeans IDE 6.1, which has many features designed to simplify developing applications. You will need to install the JavaFX plugin for NetBeans.

If you don’t have NetBeans IDE 6.1 installed, you can download NetBeans IDE 6.1 with JavaFX, a single installation package that contains NetBeans IDE 6.1 and the JavaFX plugin for NetBeans. If you already have NetBeans IDE 6.1 installed, you can add JavaFX technology support by installing the JavaFX plugin in the NetBeans update center. The JavaFX plugin for NetBeans is currently available for Windows and Mac OS/X environments. Installing the JavaFX plugin allows you to use NetBeans IDE 6.1 to create, test, debug, and deploy applications written in the compiler-based version of JavaFX Script. The plugin enhances editor and project support to include JavaFX Script files. It also provides the core libraries for the script engine and its libraries.

After you install NetBeans IDE 6.1 with JavaFX or the JavaFX plugin for NetBeans, you’re ready to build your first JavaFX application. Of course, who can resist starting with “Hello, world!”

Start by creating a project as follows:

  1. Choose File -> New Project from the main menu.
  2. In the New Project wizard, select the JavaFX category and the JavaFX Script Application project type.
  3. Click the Next button.
  4. Name the project, for instance, HelloWorldJFX.Accept the default project location or browse to select a different location.
  5. Leave the Create Main Class checkbox checked and the other default settings unchanged.
  6. Click the Finish button.

As Figure 1 shows, the IDE creates the project directory in the specified project folder and gives it the same name as your project, HelloWorldJFX. Expand the HelloWorldJFX project. Notice the Main.fx class file below the helloworldjfx package in the Source Packages node. The IDE creates the Main.fx file because the Create Main Class checkbox was checked when you created the project. This is the file that will hold the source code for the application.

Figure 1. HelloWorldJFX project files

 
Let’s put some source code in the Main.fx file. Right click on Main.fx in the Projects window, then select Open. The file opens to display the following contents:

   /*     * Main.fx     *     * Created on ...     */     package helloworldjfx;     /**     * @author ...     */     // place your code here

 
Replace the line // place your code here with the following code:

   import javafx.ext.swing.Label;     Label {        text: "Hello, world!"    }

 
The JavaFXScript 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 Ctrl + Space keys activates code completion in the editor.

In addition, the JavaFX Script plugin provides a preview feature that you can use to view the results of your application without having to compile and run it first. Changes that you make to the source file are immediately reflected in the preview pane. The preview feature is currently disabled on the Mac OS X platform.

Click the Enable Preview button preview icon to enable the preview feature. You’ll see the output just above the editor, as shown in Figure 2.

Figure 2. Your Basic “Hello, world!”

 
Not impressed? OK, although I’m really just trying to show you how to get set up, I’ll try 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 dialog boxes.

No responses yet

Aug 05 2008

Learning Curve Journal, Part 1: Exploring JavaFX Script (2)

Published by mac0002 under technology

Setting Up the Java Platform

As a developer, you no doubt have a JDK on your system. However, if you haven’t updated your system in a while, make sure you have Java SE 6. The Learning Curve Journal focuses on the compiler-based version of JavaFX Script and its support in NetBeans IDE 6.1. To install and use NetBeans IDE 6.1 with JavaFX technology, it is recommended that you install the latest level of Java SE 6 on your system, which currently is Java SE 6 Update 10 Beta. 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, which currently is Java for Mac OS X 10.5, Update 1, 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 javafx.com and Project OpenJFX web sites provide demo resources and the latest documentation you need to get accurate information.

Some of you will want to start programming immediately, barely reading a word of the language reference. 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. The documents on the JavaFX Reference page are a good place to start. You can find links there to reference documents such as the The JavaFX Script Programming Language Reference as well as links to many articles and tutorials such as Getting Started With JavaFX Technology and Creating A Simple JavaFX Application Using NetBeans IDE.

Creating a JavaFX Application

After you’ve read at least some of the language reference document, it’s time to build a simple JavaFX application. Although you can build and run a JavaFX application manually from a command line, let’s do it using NetBeans IDE 6.1, which has many features designed to simplify developing applications. You will need to install the JavaFX plugin for NetBeans.

If you don’t have NetBeans IDE 6.1 installed, you can download NetBeans IDE 6.1 with JavaFX, a single installation package that contains NetBeans IDE 6.1 and the JavaFX plugin for NetBeans. If you already have NetBeans IDE 6.1 installed, you can add JavaFX technology support by installing the JavaFX plugin in the NetBeans update center. The JavaFX plugin for NetBeans is currently available for Windows and Mac OS/X environments. Installing the JavaFX plugin allows you to use NetBeans IDE 6.1 to create, test, debug, and deploy applications written in the compiler-based version of JavaFX Script. The plugin enhances editor and project support to include JavaFX Script files. It also provides the core libraries for the script engine and its libraries.

No responses yet

Aug 05 2008

Learning Curve Journal, Part 1: Exploring JavaFX Script part1

Published by mac0002 under technology

pass4side

In August and September 2007, John O’Conner of the Sun Developer Network wrote a series titled “Learning Curve Journal” designed to help users get started with the JavaFX Script programming language (shortened to JavaFX Script in the remainder of this article). A number of significant advances have been made to the language since then. Perhaps most important is the availability of a compiler-based version of JavaFX Script, which replaces the earlier interpreter-based version of the language. The Learning Curve Journal described the use of the interpreter-based version of the language. The Learning Curve Journal has been updated to show you how to use the compiler-based version of the language. Other changes have been made to make the articles current.

As before, Part 1 of the series gets you started with a simple JavaFX program, that is, a simple program written in the JavaFX Script language. You’ll learn how to set up your environment for programming in JavaFX Script and how to build and run a JavaFX program. Part 2 focuses on the declarative style of coding enabled by JavaFX Script. You’ll see how this style can make the code for a graphical application simpler and more intuitive. Part 3 shows you how to use JavaFX Script functions to implement actions in a Java FX program. Part 4 demonstrates how to use JavaFX Script to access a web service. In doing that, it also shows how easy it is to access Java technology classes, such as Swing classes, from JavaFX Script.

JavaFX Script is a new scripting language that developers can use to create dynamic graphical content. On the desktop, the language provides libraries to help you use the Swing user interface (UI) 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. In other environments, such as mobile systems, JavaFX Script makes use of user interface technologies other than Swing. JavaFX Script enables you to write visually rich applications that run across platforms and operating environments.

The language provides both declarative and procedural 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 the following:

No responses yet