Java Reference
In-Depth Information
The previous code snippets show the following three ways of accessing resources in JavaFX:
F __DIR__ pseudo-variable —often, you will see the use of JavaFX's pseudo variable
__DIR__ , used when specifying the location of a resource. It is a special variable
that stores the String value of the directory where the executing class that referenced
__DIR__ is located. This is valuable, especially when the resource is embedded in
the application's JAR file. At runtime, __DIR__ stores the location of the resource in
the JAR file, making it accessible for reading as a stream. In the previous code, for
example, the expression {__DIR__}image.png explodes as jar:file:/users
/image.png .
F Direct reference to local resources —when the application is deployed as a desktop
application, you can specify the location of your resources using URLs that provides
the absolute path to where the resources are located. In our code, we use file:/users/
home/vladimir/javafx/ch005/source-code/ src/image.png as the absolute
fully qualified path to the image file image.png .
F Direct reference to remote resources —inally, when loading media assets, you are
able to specify the path of a fully-qualified URL to a remote resource using HTTP.
As long as there are no subsequent permissions required, classes such as Image
and Media are able to pull down the resource with no problem. For our code, we
use a URL to a Flickr image
a6db13ce1b_d.jpg .
There's more...
Besides __DIR__ , JavaFX provides the __FILE__ pseudo variable as well. As you may
well guess, __FILE__ resolves to the fully qualified path of the of the JavaFX script file that
contains the __FILE__ pseudo variable. At runtime, when your application is compiled, this
will be the script class that contains the __FILE__ reference.
Loading and displaying images with
If you have already checked out recipes in previous chapters, you know by now that
JavaFX provides classes, which make it easy to load and display images. This recipe
takes a closer look at the mechanics provided by the Image API to load and display
images in your JavaFX applications.
Search WWH ::

Custom Search