Test Questions & Answers | JavaFX GUI Programming and – Ch12 - Java Control Structures 7e Test Bank by Tony Gaddis. DOCX document preview.

Test Questions & Answers | JavaFX GUI Programming and – Ch12

Starting Out with Java: From Control Structures through Objects 7e (Gaddis)

Chapter 12 JavaFX: GUI Programming and Basic Controls

TRUE/FALSE

1. The command line interface is an event-driven interface.

2. When programming in JavaFX, you should think of the GUI objects as nodes in a tree-like hierarchical structure known as a scene graph.

3. To display an image in a JavaFX application, you use either the Image or ImageView class.

4. The Pos type must be imported from the javafx.geometry package.

5. To preserve an image's aspect ratio you can use the ImageView class's PreserveAspectRatio method.

6. Layout containers provide methods for fine-tuning the way controls are arranged.

7. The BorderPane container always displays its content in five regions which are top, bottom, left, right, and center and each region must be used.

8. A GUI program automatically stops executing when the end of the main method is reached.

9. When a splash screen is displayed, the application does not load and execute until the user clicks the splash screen image with the mouse.

10. An event object is created when an event takes place.

11. An event handler class will not be executed unless it has been registered with the correct control.

MULTIPLE CHOICE

1. Which of the following is not a way a user can interact with a computer?

a.

command line

b.

console interface

c.

GUI

d.

All of these are ways for a user to interact with a computer.

2. Programs that operate in a GUI environment must be __________.

a.

event driven

c.

dialog boxes

b.

in color

d.

layout managers

3. The __________ layout container arranges its contents with columns and rows.

a.

GridLayout

c.

Grid

b.

GridPane

d.

CellManager

4. To add padding to an HBox you can call the __________ method.

a.

HBoxPadding

c.

setPadding

b.

SetHBoxPadding

d.

setHboxPad

5. The HBox object's setPadding method takes a(n) __________as its argument.

a.

Insets method

c.

boolean

b.

Insets object

d.

integer

6. A(n) __________ is an action that takes place in an application, such as the clicking of a button.

a.

instance

b.

effect

c.

case

d.

event

7. One important difference between the command line interface and a GUI interface is that __________.

a.

in command line the background color of the monitor will always be black but in a GUI it can be any color

b.

in a GUI environment the user determines the order in which things happen while the user has no control over the order or events in a command line interface

c.

users must type information in a command line interface but, when using a GUI, typing is never required

d.

All of these are important differences.

8. To display an image in a JavaFX application you must __________.

a.

include either the Image or the ImageView class

b.

include both the setImage and the ViewImage classes

c.

include both the Image and the ImageView classes

d.

include either the setImage or the ViewImage class

9. For this question, assume myView references an ImageView object. In order to preserve the image's aspect ratio (so it does not appear stretched or distorted), you should use which of the following?

a.

myView.setPreserveRatio(false);

b.

myView.setPreserveRatio(true);

c.

myView.setPreserveRatio();

d.

Either (a) or (c) would work.

10. In order to leave 15 pixels of space in an HBox container, use which of the following statements?

a.

myhbox = setPadding(15);

b.

myhbox.setPadding(15);

c.

myhbox.setPadding.Insets(15);

d.

myhbox.setPadding(new Insets(15));

11. The __________ layout container arranges the contents into cells, similar to a spreadsheet.

a.

GRID

c.

GridPaneObj

b.

GridPane

d.

CellPane

12. The Application class's __________ method is the main entry point for a JavaFX application.

a.

start

b.

init

c.

addWindow

d.

mainFX

13. An action that takes place while a program is running is a(n) __________.

a.

event source

c.

event

b.

event handler

d.

event object

14. When an event takes place, the control responsible for the event creates an event __________.

a.

source

b.

object

c.

handler

d.

firing

15. The process of connecting an event handler object to a control is called __________ the event handler.

a.

passing

b.

registering

c.

applying

d.

rendering

16. Which of the following import statements is required in order to write an event handler class?

a.

import javafx.event.EventHandler;

b.

import javafx.event.ActionEvent;

c.

import javafx.EventHandler;

d.

import javafx.EventHandler.event;

17. Which of the following import statements is required in order to create a BorderPane layout container?

a.

import javafx.scene.layout.Box;

b.

import javafx.scene.layout;

c.

import javafx.layout.scene.BorderPane;

d.

import javafx.scene.layout.BorderPane;

18. What method do you call to register an event handler with a Button control?

a.

setAction

c.

setOnClick

b.

onClickAction

d.

setOnAction

19. To create a TextField control, you use the __________ class which is in the __________ package.

a.

TextField, javafx.text.control

b.

TextField, javafx.scene.control

c.

TextBox, javafx.scene.control

d.

TextField, javafx.textfield

20. To retrieve text that a user has typed into a TextField control, you call the __________ method.

a.

inputText

c.

getText

b.

getInput

d.

getInputText

21. If a BorderPane region does not contain anything, __________.

a.

the region will appear gray by default

b.

the region will not appear in the GUI

c.

an error will occur

d.

content from an adjacent region will be duplicated to appear in the empty region

22. If you set a scene's size to a width and height that is smaller than the width and height of the image to be displayed ___________.

a.

only part of the image will be displayed

b.

the image will only occupy part of the window

c.

the scene will automatically be resized to fit the image

d.

the image will automatically be resized to fit the window

23. What does the following statement do?

Image puppy = new Image("file:C:\\images\terrier.jpg");

a.

It creates an instance of the ImageView class with the terrier.jpg file passed to the constructor.

b.

It loads an image named "images\terrier.jpg" and stores the image in the Image variable.

c.

It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive.

d.

Nothing; it is not possible to include a path to a file when using the Image class.

24. Assuming three ImageView objects named puppy, kitten, and bunny have been created, what does the following statement do?

HBox hbox = new HBox(5, puppy, kitten, bunny);

a.

The number 5 refers to the number of ImageView objects so there will be two empty spots for two more ImageView objects.

b.

There will be five pixels of space between the controls horizontally in the container.

c.

The controls will be displayed vertically with five pixels between them.

d.

The statement does nothing; it contains an error.

25. Which of the following statements correctly adds a label to the first row and second column of a GridPane object?

a.

gridpane.add(myLabel, 1, 2);

b.

gridpane.add(myLabel, 2, 1);

c.

gridpane.add(myLabel, 0, 1);

d.

gridpane.add(myLabel, 1, 0);

MULTIPLE RESPONSE

1. Select all that apply. Given the statement shown below, which of the following statements are true?

Scene scene = new Scene(hbox, 100, 500);

a.

The width of the scene will be 100 pixels.

b.

The height of the scene will be 100 pixels.

c.

A Scene object named scene will be created.

d.

The root node is hbox.

2. Select all that apply. Which of the following file types are supported by the Image class?

a.

BMP

b.

JPEG

c.

GIF

d.

PNG

3. Select all that apply. Which of the following are constructors of the BorderPane class?

a.

BorderPane()

b.

BorderPane(top, bottom)

c.

BorderPane(center)

d.

BorderPane(left, right)

e.

BorderPane(center, top, right, bottom, left)

4. Select all that apply. Which of the following are regions where content can be displayed in the BorderPane layout container?

a.

top and bottom

c.

above and below center

b.

center

d.

left and right

5. Select all that apply. Which of the following are nodes that can be used in a scene graph?

a.

tree node

b.

root node

c.

leaf node

d.

branch node

6. Select all that apply. It may be possible to simplify event handler code by using which of the following?

a.

nested classes

c.

lambda expressions

b.

anonymous inner classes

d.

listener expressions

Document Information

Document Type:
DOCX
Chapter Number:
12
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 12 JavaFX GUI Programming and Basic Controls
Author:
Tony Gaddis

Connected Book

Java Control Structures 7e Test Bank

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party