Java Reference
In-Depth Information
F Module-variables—as a code unit, a module can also include top-level variable
declarations. Beside the regular public scope, variables can also be marked
public-read which indicates a read-only public variable (such as the size
variable in the code). Script-only variables are only available to members of
the module.
You can read more about access modifiers in the There's more section next.
There's more...
Before leaving this recipe, we should take a closer look at some important topics related to
the material that we just covered.
Script versus module
How do you know when a file is a script or a module? Well, there are some rules that define
the qualifications:
The following rules qualify a file as a regular script:
F A script can have classes, functions, and variable members
F A script can have dangling expressions (outside of a function or class code block)
F A script cannot have any public variable members
F A script can include the special function run() to launch it
A script file is a module that has the following:
F A module can have classes, functions, and variable members
F A module cannot have dangling expressions (all expressions are in classes or
function code blocks)
F A module can have public variable members
F A well-designed module should not implement the function run()
Organize your code into packages
Similar to Java, JavaFX script files can be further organized as packages. A package is simply
a directory structure where you can arrange your scripts, modules, and other resources in a
way which provides separation and grouping structures. To create a package, you create the
directory structure reflecting how you want your script files to be organized.
The structure of the directories translates into the dot notation of the package name. For
instance, if you nest your directories as com/mycompany/anim , then your package is
com.mycompany.anim . Scripts and modules that belong to a package must declare their
membership with the statement package com.mycompany.anim . Client code interested
in using items in the package must import the package using the statement import com.
mycompany.anim .
Search WWH ::

Custom Search