Game Development Reference
In-Depth Information
object is therefore a type of Node object in the JavaFX Scene Graph that is used for
painting a view, using the data contained in an Image object. The class has methods
that allow image resampling (resizing), and, as with the Image class, you can lock the
aspect ratio for scaling as well as specify the resampling algorithm (smoothing quality).
The Java class hierarchy for the ImageView class starts with the java.lang.Object
master class and uses this class to create the javafx.scene.Node class, which is then
employed to create an ImageView Node subclass. As Figure 6-4 illustrates (l. 10), like
the Image class, ImageView is contained in the JavaFX image package. The
ImageView class uses the following Java class inheritance hierarchy structure:
java.lang.Object
> javafx.scene.Node
> javafx.scene.image. ImageView
The ImageView class provides three different (overloaded) ImageView() construct-
or methods. These range from an empty constructor (which is the one you are going to
use later on, in your code); to one that takes an Image object as its parameter; to one
that takes a URL String object as the parameter and creates the Image object automat-
ically. To create an ImageView object, the simple (empty) ImageView() constructor
method uses the following format:
ImageView()
You will be employing this constructor method so that I can show you how to use
the .setImage() method call to load an Image object into an ImageView object. If you
want to avoid using the .setImage() method call, you can use the overloaded construct-
or method, which has the following format:
ImageView(Image image )
So, to set up an ImageView “explicitly” and wire it to the Image object looks like
this:
splashScreenBackplate = new ImageView();
// This
uses the empty constructor method approach
splashScreenBackplate.setImage( splashScreen );
You can condense this into one line of code, using an overloaded constructor meth-
od, structured as follows:
Search WWH ::




Custom Search