Chapter 16 JavaFX UI Controls and Multimedia
Section 16.2 Labeled and Label
1. To create a label with the specified text, use .
a. new Labelled();
b. new Label();
c. new Labelled(text);
d. new Label(text);
#
2. To set a red color for the text in the label lbl, use .
a. lbl.setFill(Color.red);
b. lbl.setTextFill(Color.red);
c. lbl.setFill(Color.RED);
d. lbl.setTextFill(Color.RED);
#
3. are properties in Labelled.
a. alignment
b. contentDisplay
c. graphic
d. text
e. underline
#
4. To set the node to the right of the text in a label lbl, use .
a. lbl.setContentDisplay(ContentDisplay.TOP);
b. lbl.setContentDisplay(ContentDisplay.BOTTOM);
c. lbl.setContentDisplay(ContentDisplay.LEFT);
d. lbl.setContentDisplay(ContentDisplay.RIGHT);
#
6. is a superclass for Label.
a. Scene
b. Labelled
c. ButtonBase
d. Control
e. Node
#
Section 16.3 Button
8. Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
HBox pane = new HBox(5);
Image usIcon = new
Image(“http://www.cs.armstrong.edu/liang/image/usIcon.gif”);
Button bt1 = new Button(“Button1”, new ImageView(usIcon));
Button bt2 = new Button(“Button2”, new ImageView(usIcon));
pane.getChildren().addAll(bt1, bt2);
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle(“Test”); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited JavaFX
* support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
a. Two buttons displayed with the same icon.
b. Only bt2 displays the icon and bt1 does not display the icon.
c. Only bt1 displays the icon and bt2 does not display the icon.
d. Two buttons displayed with different icons.
#
9. Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
StackPane pane = new StackPane();
Button bt1 = new Button(“Java”);
Button bt2 = new Button(“Java”);
Button bt3 = new Button(“Java”);
Button bt4 = new Button(“Java”);
pane.getChildren().addAll(bt1, bt2, bt3, bt4);
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle(“Test”); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited JavaFX
* support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
a. One button is displayed with the text “Java”.
b. Two buttons are displayed with the same text “Java”.
c. Three buttons are displayed with the same text “Java”.
d. Four buttons are displayed with the same text “Java”.
#
10. Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
Pane pane = new FlowPane();
Button bt1 = new Button(“Java”);
Button bt2 = new Button(“Java”);
Button bt3 = new Button(“Java”);
Button bt4 = new Button(“Java”);
pane.getChildren().addAll(bt1, bt2, bt3, bt4);
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle(“Test”); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited JavaFX
* support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
a. One button is displayed with the text “Java”.
b. Two buttons are displayed with the same text “Java”.
c. Three buttons are displayed with the same text “Java”.
d. Four buttons are displayed with the same text “Java”.
#
5. is a superclass for Button.
a. Label
b. Labelled
c. ButtonBase
d. Control
#
7. The setOnAction method is defined in .
a. Label
b. Labelled
c. Node
d. ButtonBase
e. Button
#
Section 16.4 CheckBox
11. checks whether the CheckBox chk is selected.
a. chk.getSelected()
b. chk.selected()
c. chk.isSelected().
d. chk.select()
#
12. Which of the following statements are true?
a. CheckBox inherits from ButtonBase.
b. CheckBox inherits from Button.
c. CheckBox inherits from Labelled.
d. CheckBox inherits from Control.
e. CheckBox inherits from Node.
#
Section 16.5 RadioButton
13. Which of the following statements are true?
a. RadioButton inherits from ButtonBase.
b. RadioButton inherits from Button.
c. RadioButton inherits from Labelled.
d. RadioButton inherits from Control.
e. RadioButton inherits from Node.
#
14. checks whether the RadioButton rb is selected.
a. rb.getSelected()
b. rb.selected()
c. rb.isSelected().
d. rb.select()
#
15. Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
Pane pane = new FlowPane();
ToggleGroup group = new ToggleGroup();
RadioButton rb1 = new RadioButton(“Java”);
RadioButton rb2 = new RadioButton(“C++”);
pane.getChildren().addAll(rb1, rb2);
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle(“Test”); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited JavaFX
* support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
a. The program displays two radio buttons. The two radio buttons are grouped.
b. The program displays one radio button with text Java.
c. The program displays two radio buttons. The two radio buttons are not grouped.
d. The program displays one radio button with text C++.
#
Section 16.6 TextField
16. Which of the following statements are true?
a. TextField inherits from TextInputControl.
b. TextField inherits from ButtonBase.
c. TextField inherits from Labelled.
d. TextField inherits from Control.
e. TextField inherits from Node.
#
17. The properties can be used in a TextField.
a. text
b. editable
c. alignment
d. prefColumnCount
e. onAction
#
18. Which of the following statements are true?
a. You can specify a horizontal text alignment in a text field.
b. You can specify the number of columns in a text field.
c. You can disable editing on a text field.
d. You can create a text field with a specified text.
#
19. The method gets the contents of the text field tf.
a. tf.getText(s)
b. tf.getText()
c. tf.getString()
d. tf.findString()
#
20. Which of the following statements are true?
a. PasswordField inherits from TextInputControl.
b. PasswordField inherits from TextField.
c. PasswordField inherits from Labelled.
d. PasswordField inherits from Control.
e. PasswordField inherits from Node.
#
Section 16.7 TextArea
22. Which of the following statements are true?
a. You can specify a horizontal text alignment in a text area.
b. You can specify the number of columns in a text area.
c. You can disable editing on a text area.
d. You can create a text field with a specified text area.
#
23. To wrap a line in a text area ta, invoke .
a. ta.setLineWrap(false)
b. ta.setLineWrap(true)
c. ta.WrapLine()
d. ta.wrapText()
e. ta.setWrapText(true)
#
24. To wrap a line in a text area jta on words, invoke .
a. jta.setWrapStyleWord(false)
b. jta.setWrapStyleWord(true)
c. jta.wrapStyleWord()
d. jta.wrapWord()
#
21. The method appends a string s into the text area ta.
a. ta.setText(s)
b. ta.appendText(s)
c. ta.append(s)
d. ta.insertText(s)
#
25. Which of the following statements are true?
a. TextArea inherits from TextInputControl.
b. TextArea inherits from TextField.
c. TextArea inherits from Labelled.
d. TextArea inherits from Control.
e. TextArea inherits from Node.
#
Section 16.8 ComboBox
28. returns the selected item on a ComboBox cbo.
a. cbo.getSelectedIndex()
b. cbo.getSelectedItem()
c. cbo.getSelectedIndices()
d. cbo.getSelectedItems()
e. cbo.getValue()
#
29. The method adds an item s into a ComboBox cbo.
a. cbo.add(s)
b. cbo.addChoice(s)
c. cbo.addItem(s)
d. cbo.addObject(s)
#
30. Which of the following statements are true?
a. ComboBox inherits from ComboBoxBase.
b. ComboBox inherits from ButtonBase.
c. ComboBox inherits from Labelled.
d. ComboBox inherits from Control.
e. ComboBox inherits from Node.
#
31. You can use the properties in a ComboBox.
a. value
b. editable
c. onAction
d. items
e. visibleRowCount
#
26. How many items can be added into a ComboBox object?
a. 0
b. 1
c. 2
#
27. How many items can be selected from a ComboBox at a time?
a. 0
b. 1
c. 2
d. Unlimited
#
Section 16.9 ListView
32. are properties for a ListView.
a. items
b. orientation
c. selectionModel
d. visibleRowCount
e. onAction
#
33. Which of the following statements are true?
a. ListView inherits from ComboBoxBase.
b. ListView inherits from ButtonBase.
c. ListView inherits from Labelled.
d. ListView inherits from Control.
#
34. The statement for registering a listener for processing list view item change is .
a. lv.getItems().addListener(e –> {processStatements});
b. lv.addListener(e –> {processStatements});
c. lv.getSelectionModel().selectedItemProperty().addListener(e –> {processStatements});
d. lv.getSelectionModel().addListener(e –> {processStatements});
#
Section 16.10 ScrollBar
35. are properties of ScrollBar.
a. value
b. min
c. max
d. orientation
e. visibleAmount
#
36. The statement for registering a listener for processing scroll bar value change is .
a. sb.addListener(e –> {processStatements});
b. sb.getValue().addListener(e –> {processStatements});
c. sb.valueProperty().addListener(e –> {processStatements});
d. sb.getItems().addListener(e –> {processStatements});
#
Section 16.11 Slider
37. are properties of Slider.
a. value
b. min
c. max
d. orientation
e. visibleAmount
#
38. The statement for registering a listener for processing slider change is .
a. sl.addListener(e –> {processStatements});
b. sl.getValue().addListener(e –> {processStatements});
c. sl.valueProperty().addListener(e –> {processStatements});
#
Section 16.13 Video and Audio
39. Which of the following statements are true?
a. A Media can be shared by multiple MediaPlayer.
b. A MediaPlayer can be shared by multiple MediaView.
c. A MediaView can be placed into multiple Pane.
d. A Media can be downloaded from a URL.
#
40. You can use the methods to control a MediaPlayer.
a. start().
b. stop().
c. pause().
d. play().
#
41. You can use the properties to control a MediaPlayer.
a. autoPlay
b. currentCount
c. cycleCount
d. mute
e. volume
#
42. You can use the properties in a MediaView.
a. x
b. y
c. mediaPlayer
d. fitWidth