Working with JavaFX ScriptTM Demos

Working with JavaFX Demo files in JMaker

The demos are part of the JavaFX download from the JavaFX website.
The JavaFX demos include these project folders:

  • C:\JDK6\source\demos (this becomes the source path in this example)
    • casual
    • demo
    • javafxpad
    • projects
    • studiomoto
    • svg
    • tesla
    • tutorial

In this example:

  • The demos were copied into C:\JDK6\source (see image below)
  • demos\demo\DemoLauncher.fx was loaded into an Edit Window to be run
  • The sourcepath was set as C:\JDK6\source\demos\
  • Packaged was selected in the java options and/or in the Edit Window Options menu
  • The java -cp option (see below) was set to
    • .;C:\JDK6\jre\lib\javafxrt.jar;C:\JDK6\jre\lib\Filters.jar;C:\JDK6\jre\lib\swing-layout.jar;C:\JDK6\source\demos
    • Note that the -cp (classpath) java option shows the path to:
      • javafxrt.jar
      • Filters.jar
      • swing-layout.jar
      • C:\JDK6\source\demos\ (the location of the source files including their package name/folder)
  • DemoLauncher.fx was run in the Edit Window
The Run Process Window shows the following command:

C:\JDK6\bin\java -cp .;C:\JDK6\jre\lib\javafxrt.jar;C:\JDK6\jre\lib\Filters.jar;C:\JDK6\jre\lib\swing-layout.jar;C:\JDK6\source\demos net.java.javafx.FXShell demo.DemoLauncher


This images shows how the JavaFX demo files have been copied into the JDK's source folder

The folder names (casual, demo, javafxpad, etc) are also the package names. The DemoLaucher.fx script is in the demo folder.

How to run one of the demo without using the DemoLaucher

You will probably need to add a jar file to the -cp option.
To run the javafxpad demo alone the -cp becomes:
.;C:\JDK6\jre\lib\javafxrt.jar;C:\JDK6\jre\lib\Filters.jar;C:\JDK6\jre\lib\swing-layout.jar;C:\JDK6\source\demos\javafxpad\lib\jfxFormat.jar;C:\JDK6\source\demos
Here is the -cp broken down into pieces for clarity:

  • .;
  • C:\JDK6\jre\lib\javafxrt.jar;
  • C:\JDK6\jre\lib\Filters.jar;
  • C:\JDK6\jre\lib\swing-layout.jar;
  • C:\JDK6\source\demos\javafxpad\lib\jfxFormat.jar;
  • C:\JDK6\source\demos

Note that in this example the semi-colon ';' is the path separator

Or, in other words:

The -cp classpath option tells the java program where to find files:

What file(s)Location
local class files.
javafxrt.jarC:\JDK6\jre\lib\javafxrt.jar
Filters.jarC:\JDK6\jre\lib\Filters.jar
swing-layout.jarC:\JDK6\jre\lib\swing-layout.jar
jfxFormat.jarC:\JDK6\source\demos\javafxpad\lib\jfxFormat.jar
*the "packaged" source.fx filesC:\JDK6\source\demos

Set the -cp in the java options window - see below

Here are how the java options are set in this example

Note:

  • The command checkbox is checked and contains java
  • The -cp option is checked and contains the classpath
  • The other checkbox is checked and contains net.java.javafx.FXShell
  • The packaged checkbox is checked because the JavaFX demos are packaged
To run the javafxpad.fx demo:
  1. Goto the demos\javafxpad\ folder and open the main.fx into an Edit Window
  2. Click on the Run button

The Run Process Window output after running the javafxpad.fx's main.fx file:
  1. C:\JDK6\bin\java -cp .;C:\JDK6\jre\lib\javafxrt.jar;C:\JDK6\jre\lib\Filters.jar;C:\JDK6\jre\lib\swing-layout.jar;C:\JDK6\source\demos\javafxpad\lib\jfxFormat.jar;C:\JDK6\source\demos net.java.javafx.FXShell javafxpad.Main
  2. compile thread: Thread[AWT-EventQueue-0,6,main]
  3. compile 2.875
  4. javax.swing.JFormattedTextField[,0,0,0x0,...
  5. baseline = 13
  6. init: 3.954
  7. compile thread: Thread[AWT-EventQueue-0,6,main]
  8. compile 0.031
  9. C:\JDK6\bin\java -cp .;C:\JDK6\jre\lib\javafxrt.jar;C:\JDK6\jre\lib\Filters.jar;C:\JDK6\jre\lib\swing-layout.jar;C:\JDK6\source\demos\javafxpad\lib\jfxFormat.jar;C:\JDK6\source\demos net.java.javafx.FXShell javafxpad.Main
  10. is done.

Note:

  • Your output may be different
  • Lines are numbered for clarity

I am tired of changed the -cp option for the various demo lib/.jar files

One solution is to copy all the demo lib/.jar files into a folder (JDK/jre/lib folder for example). Then you would add that folder path to your classpath.

0 comments:

Yang Sering Dibaca: