JavaFX is a new platform for creating and deploying rich Internet applications inside a lightweight Java virtual machine. JavaFX Studio works as an Eclipse plugin for developing and deploying JavaFX applications. JavaFX Studio comes with numerous features and wizards to make JavaFX application development better.
Table 2.1. Key Features of Exadel JavaFX Studio
| Feature | Description |
|---|---|
| Multi project support | If a project depends on some other project the plug-in can resolve the dependencies during compiling, launching and code-assist. |
| Code Assist | Completes your code statements faster and with more accuracy |
| JavaFX Examples | Exadel JavaFX Studio enables you to open a example project (standard Sun JavaFX examples) and run it from the studio |
Install JavaFX SDK
Download JavaFX SDK for Windows or Linux. Follow the installation instructions.
Install Eclipse
The Plugin requires Eclipse 3.5. We recommend downloading "Eclipse IDE for Java EE Developers" for Windows or Linux. Then follow the installation instructions.
Install Plugin
Download the plugin(plugin download page), unzip the downloaded file
Start Eclipse IDE
On the Help menu select Software Updates
In the Software Updates and Add-ons dialog click on the Available Sofware tab
Click on the Add Site button, choose Local
Navigate to the folder with unzipped plugin, open it, select the "eclipse" directory and press Ok
You will see the "Exadel JavaFX 1.1.1 Update Site" option in the list. Check the option and press Install.
Follow the steps in the installation wizard.
Check the JavaFX IDE option and press Next
Confirm that you accept the terms of the license agreement and hit Finish to complete the installation process
When the wizard finishes, you will be prompted to restart Eclipse.
In this chapter you will learn how to create projects with Exadel JavaFX Studio IDE. The fist project is quite elementary, you will create a JavaFX script file, set up the configuration and run the script. Though the second project described in the chapter is more complex, it shows how to use both scripts and classes in your application.
This section will tell how to create a simple JavaFX with JavaFX plugin. Following the steps of this section you will be able to create a JavaFX application that runs as a standalone application and prints "Hello World!"
Once the plug-in is installed, you can create a JavaFX project.
Select File > New > Other...> JavaFX > JavaFX Project and click Next
Alternatively, if you have the JavaFX perspective activated, you can just click File > New and select JavaFX Project.
The New JavaFX project wizard will guide you through the step required to create a new project.
Type in the project name in the Project name field first. By default the project will be added to your current workspace.
Then you need to configure your JavaFX Runtime Configuration.
Click the Configure button, then press Add to navigate to the folder where the JavaFX SDK is installed
If JavaFX SDK is already configured you will see that the Use default JavaFX runtime (currently ' current SDK version ' ) option is selected. If you wish to use other SDK version you can point to it by selecting Alternative and clicking the Configure button.
You also need to specify the type of application you are about to create in the Profile section.
Select Desktop
The Working sets option group lets you show only resources, children of resources, and parents of resources contained in the working set. The problems view, tasks view and bookmarks view can all be filtered based on a working set. When using the search facility, you can also use working sets to restrict the set of elements that are searched.
When you are done with this dialog proceed to the next one by clicking the Next button.
The Project layout option group enables you to configure where your source and class file are to be located. By default they are located in the src and bin folder respectively. You can alter the layout configuration by clicking on Configure default.. .
Click Next to set up the Java build settings. Leave everything here with default values.
Press Finish to complete the wizard's job
Now you see in your Project Explorer the project you've just created.
Now you need to add a JavaFX script to your project.
Create a new package in the src folder
Right-click on the newly created package, select New > Other...> JavaFX > JavaFX Script and click Next
Type in the file name for the script and specify the folder where it will be placed.
Notice, that you don't need to add the "fx" extension, as it's added automatically.
Click Next to open the next dialog of the wizard
The dialog gives you an option to generate a simple JavaFX Stage, you can specify the title, width and height variables of the Stage with the corresponding fields.
When the Finish button is pressed you will see the script file in the Package Explorer and the script itself in the editor.
You can now run the "Hello World" JavaFX application. What you need to do now is to configure your Run Configuration
On the Run menu click Run Configurations
In the Run Configurations dialog double-click on the JavaFX application option to create a new configuration
In this dialog you need to define the project for which you are creating the configuration, point to the .fx you've just created, make sure the JavaFX runtime is enable for the configuration. Leave the Profile and Run as fields with default values: "desktop" and "Applicaton" respectively.
Hit Run to launch the project
You will see the "Hello World!" message on your screen.
In the previous section of the guide you have learned how to create a simple JavaFX project following wizard's steps. If you are familiar with JavaFX technology it will be sufficient to start developing your application. However, if you are new to JavaFX you can take a look at JavaFX example projects.
To explore a JavaFX example you should do the following:
Navigate to File > New > Other...> Examples > JavaFX Examples (for faster navigation you can type in "JavaFX Examples" in the input field), select JavaFX Example and press Next
Configure the project
Give a meaningful name to the project
Specify the JavaFX runtime environment or use the default on if it was configured previously
Define the application type in the Profile group
Choose an example project in the Available Example list box
You can optionally add the project to a working set
Press Next to set up JRE and project layout parameters if you need to, otherwise you can hit Finish to complete the wizard
You can now have a look a the source code of the example application and run it. For more details on running a JavaFX application from Exadel JavaFX Studio please read the Launching JavaFX Project chapter of the guide.
Now we will make something more complex - a puzzle game.
Create a new project and make a package in the src folder.
Generate an empty script file, call it Game.fx (File > New > Other...> JavaFX > JavaFX Script). Configure it as it's shown in the previous Creating Simple JavaFX Project, except for the last step: do not generate any content for the script.
When you see the newly-created file in the Package Explorer double-click on the file and add the following code:
...
package com.exadel;
import javafx.ext.swing.SwingButton;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.stage.Stage;
def cellSize:Number = 40;
def puz = PuzzleGrid { boxDim:3 };
def gridFont = Font
{ name: "Arial Bold"
size: 20
};
Stage
{ title: "Game"
visible: true
scene: Scene
{ content: for(idx in [0..<puz.gridSize])
{ var x:Integer = (idx mod puz.gridDim);
var y:Integer = (idx / puz.gridDim);
SwingButton
{ translateX: x * cellSize;
translateY: y * cellSize;
width: cellSize;
height: cellSize;
text: bind if(puz.grid[idx]>=1)
"{puz.grid[idx]}" else " "
font: gridFont
action: function():Void
{ var v = puz.grid[idx];
v = (v+1) mod (puz.gridDim+1);
puz.grid[idx] = v;
}
}
}
width: puz.gridDim * cellSize
height: puz.gridDim * cellSize
}
}
...
Create a class file. File > New > Other...> JavaFX > JavaFX Class
Call the file PuzzleGrid
Hit Finish
You see now the PuzzleGrid.fx file in the Package Explorer.
Double-click on the file to open it in the editor
Add the this code to the PuzzleGrid.fx file
...
package com.exadel;
public class PuzzleGrid {
public-init var boxDim:Integer = 3;
public-read def gridDim:Integer = bind boxDim*boxDim;
public-read def gridSize:Integer = bind gridDim*gridDim;
package var grid:Integer[] =
for(a in [0..<gridSize]) { 0 }
};
...
If you run the first project on the chapter you need to reconfigure your Run Configuration to set up everything for this new project, if not you need to do that from the scratch.
On the Run menu click Run Configurations , then select your current configuration or make a new one.
Select "Puzzle" project and choose the Game.fx file in the Stage field
Click the Run button to launch the project.
You should see a standalone Java application launch.
When creating a new JavaFX project the Run Configuration is set up
automatically for your project, so that you don't need to configure it manually. It
makes launching the project a very easy operation: you should click on the project to select
it and press the Run button (
) on the ToolBar.
In order to configure the default launching parameters of your application you need to click Run Configurations on the Run menu, select JavaFX Application, select your application configuration.
Another way of launching your JavaFX application with the plugin is to just select the project, right-click on it (or on script file within the project) and select Run As > Type of Application.
Moreover, having a script opened in the editor you can just call a context menu by right-clicking in the editing field and Run As > Type of Application .
If you select the Desktop profile your application can be run as:
Application
Your application is run in a separate window as a standalone application.
Applet
In case this option is selected your default browser will be pointed to an HTML file with your application as an embedded applet.
Java Web Start
The application will start using Java Web Start Technology that provides an possibility for a standalone Java software applications to be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java.
Exadel JavaFX Studio provides out-of-the-box an editor that can assist you in working with JavaFX projects.
Exadel JavaFX Studio provides a context dependent code assist/completion.
This feature is available for both script
and class files.
Code assist is available for these elements:
Syntax keywords
System classes
Attributes of system classes
User classes
Attributes of user classes
Alongside with code assist Exadel JavaFX Studio displays JavaFX help comments for or classes, method and attributes. The comments are shown next to the code assist box and in a box with yellow background.
JavaFX editor supports syntax highlighting that improves the readability of your code.
In order to identify where the block of code embraced with parentheses or curly braces starts or ends you need to place the cursor on the brace/parenthesis and you will see where the starting/ending brace/parenthesis is.
The editor also supports OpenOn feature that help you navigate you throughout the
project: this feature turns the objects into hyper-links when you hold CTRL and hover a
object. Your mouse pointer will become a hand (
), then you can click the link to open the file where the object is stored.
In order to have line numbers displayed on the left side of the JavaFX editor you need to right-click on left-hand border of the editor and check the Show Line Numbers option.
The Editor prevents you from making compiler error by highlighting them. The Editor verifies that you have equal number of opening and closing braces, that you typed correctly the name of the variable you had declared previously, missing semicolons and unresolved identifiers etc.
Exadel JavaFX Studio provides a rich set of code snippets that you can easily use developing your application. The palette with snippets is activated once you open a JavaFX file for editing the source code and the JavaFX perspective is also enabled. Or you can activate the Snippets view by going to Window > Show View > Other ... > General > Snippets.
Adding a JavaFX element to the Editor is simple, you just need to pick the element on the palette and drag and drop it to the editor. When you release the left mouse button to drop the element a dialog box where you can set the element's parameters will appear.
For example, we can add a blue circle to the kick start application we created in the Creating Simple JavaFX Project section of the guide.
Now in the Insert Template: Circle dialog you can set the parameters of the circle.
The generated code is inserted into your JavaFX file when you press the Insert button.
You can get help from other plunin users on the "Exadel JavaFX Studio -- Plug-In for Eclipse" forum.
Using JavaFX and Seam/Spring with Flamingo: Exadel Flamingo project page