Java Reference
In-Depth Information
•When the FXMLLoader loads an FXML file to create a GUI, it also initializes each of the control-
ler's instance variables that are declared with @FXML to ensure that they refer to the corresponding
GUI components in the FXML file.
•The @FXML annotation preceding a method indicates that the method can be used to specify a
control's event handler in the FXML file that describes the app's GUI.
•When the FXMLLoader creates an object of a controller class, it determines whether the class con-
tains an initialize method with no parameters and, if so, calls that method to initialize the con-
troller. This method can be used to configure the controller before the GUI is displayed.
• An anonymous inner class is a class that's declared without a name and typically appears inside
a method declaration.
• Since an anonymous inner class has no name, one object of the class must be created at the point
where the class is declared.
• An anonymous inner class can access its top-level class's instance variables, static variables and
methods, but has limited access to the local variables of the method in which it's declared—it can
access only the final local variables declared in the enclosing method's body. (As of Java SE 8,
an anonymous inner class may also access a class's effectively final local variables.)
Self-Review Exercises
25.1
Fill in the blanks in each of the following statements:
a)
A(n)
can display text and accept text input from the user.
b)
Use a(n)
to arrange GUI components into cells in a rectangular grid.
c)
JavaFX Scene Builder's window shows the structure of the GUI and allows
you to select and reorganize controls.
d)
You implement interface
to respond to events when the user moves a Slider 's
thumb.
e)
A(n)
represents the app's window.
f)
The method
is called by the FXMLLoader before the GUI is displayed.
g)
The contents of a scene are placed in its
.
h)
The elements in the scene graph are called
.
i)
allows you to build JavaFX GUIs using drag-and-drop techniques.
j)
A(n)
file contains the description of a JavaFX GUI.
25.2
State whether each of the following is true or false . If false , explain why.
a)
You must create JavaFX GUIs by hand coding them in Java.
b)
The layout VBox arranges components vertically in a scene.
c)
To right align controls in a GridPane column, set its Alignment property to RIGHT .
d)
The FXMLLoader initializes the controller's @FXML instance variables.
e)
You override class Application 's launch method to display a JavaFX app's stage.
f)
The control that the user is interacting with “has the focus.”
g)
By default, a Slider allows you to select values from 0 to 255.
h)
A node can span multiple columns in a GridPane .
i)
Every Application subclass must override the start method.
Answers to Self-Review Exercises
25.1 a) TextField . b) GridPane . c) Hierarchy . d) ChangeListener<Number> . e) Stage . f) initial-
ize . g) scene graph. h) nodes. i) JavaFX Scene Builder. j) FXML.
25.2 a) False. You can use JavaFX Scene Builder to create JavaFX GUIs without writing any
code. b) True. c) False. The name of the property is Halignment . d) True. e) False. You override class
 
Search WWH ::




Custom Search