Wednesday, September 10, 2008

JAVA FX DEMOS

A command line development of HelloWorld.fx

1 Introduction

2 Steps to follow

2.1 Download the JavaFX Shell

2.2 Include JavaFX Shell in the PATH

2.3 Create the JavaFX Program

2.4 Compile and execute


Introduction

JavaFX applications can be developed using the command line like any other Java application although it is highly recommended to use an IDE (such as NetBeans) or JavaFXPad. The Objective of this tutorial is to show that it's possible to develop JavaFX applications using command line and some of the caveats with using these tools.

Download the JavaFX Shell

Download the command line utilities from the zip file at https://openjfx.dev.java.net/servlets/ProjectDocumentList which will create a trunk/bin subdirectory containing the JavaFXShell that can be used to execute JavaFX programs.

Include JavaFX Shell in the PATH

Include the sub-directory that contains javafx.sh and javafx.bat which is in the trunk/bin sub-directory of the directory that was used to extract the zip file.


On Windows systems

You would do something which looks like

PATH=%PATH%;C:\\javafx\trunk\binThere is an additional step that needs to be done on Windows to be able to include the current directory in the classpath.

The initial part of the following line looks like:

%java% %opts% %debug% %opengl% -classpath %~dp0../javafxrt/src/javafxneeds to be changed to something like

%java% %opts% %debug% %opengl% -classpath .;%~dp0../javafxrt/src/javafxto include the current directory(.).


Create the JavaFX Program

Use your favorite editor to create the HelloWorld.fx program

HelloWorld.fx Code Preview

import javafx.ui.*;

Frame {
title: "Hello World JavaFX"
width: 200
height: 50
content: Label {
text: "Hello World"
}
visible: true
}


On Windows systems

javafx.bat HelloWorld.fx

This should bring up the HelloWorld window as shown below.

SCREEN SHOTS

STEPS:
----------

Choose the desired folder.

Make directory

E:\md ramya
E:\cd ramya
E:\ramya\md fxdemos
E:\ramya\cd fxdemos
E:\ramya\fxdemos>edit setpath.bat


< xml="true" ns="urn:schemas-microsoft-com:vml" prefix="v" namespace="">


Verify the path by typing
E:\ramya\fxdemos>path
In the same directory edit helloworld.fx





There is no need of compiling the fx file.

Then move to f:\fx\trunk\bin

In this folder, edit javafx.bat



We need not type any code in the javafx.bat file. We may see the sequence of codes which are already existing in the bat file as default.


We see a series of files in f:\fx\trunk\bin directory.

1.javafxstart.bat
2.javafxstart.sh
3.javafx.sh
4.javafx.bat


Return to parent folder:

E:\ramya\fxdemos>

Here type the following prompt:

E:\ramya\fxdemos\javafx.bat helloworld.fx




This should bring up the HelloWorld window as shown above.

When we close the helloworld window, we get returned to our parent folder e:\ramya\fxdeomos

No comments: