Game Development Reference
In-Depth Information
within the constructor method. You will be using the Insets class (object) to fine-tune
the position of the Button control bank, which you will be creating using the HBox lay-
out container. Think of these Insets objects as a way to draw a box inside another box,
which shows the spacing that you want the objects inside the rectangle to “respect”
around its edges. The simple constructor for an Insets object would use the following
format:
Insets(double topRightBottomLeft )
This constructor uses a single value for all the spacing sides (topRightBottomLeft),
and an overloaded constructor allows you to specify each of these values separately,
like this:
Insets(double top , double right , double bottom , double
left )
These values need to be specified in this order. An easy way to remember this is by
using an analog clock. A clock has “12” at the top, “3” at the right, “6” at the bottom,
and “9” at the left. So, starting at high noon (for you western genre lovers out there),
always work clockwise, the way the hands move around a clockface, and you will have
a great way to remember how to specify the Insets values in the “uneven values” con-
structor method. You will soon be using the Insets class to position the Button control
bank, which are initially “stuck” in the bottom-left corner of the splash screen design,
away from the left-hand side and bottom of the screen, using two of these four insets
positioning parameters.
The JavaFX HBox Class: Using a Layout Container in
a Design
Because Button objects cannot be positioned easily, I will be placing the four Button
objects in a layout container from the javafx.scene.layout package called HBox ,
which stands for Horizontal Box . This public class arranges things in a row, and be-
cause you want the buttons to be aligned at the bottom of the splash screen, you use the
Parent node for four Button control nodes, which will become children ( leaf nodes) of
this HBox branch node. This will create a bank of UI buttons that can be positioned
(moved around) together as a single unit of the splash screen design.
Search WWH ::




Custom Search