CSCI 2351: Object-Oriented Design - Ch. 14 & 15 Quizzes

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/47

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

48 Terms

1
New cards

Why is JavaFX preferred? Select all that apply.

a. JavaFX provides a multi-touch support for touch-enabled devices such as tablets and smart phones.
b. JavaFX is much simpler to learn and use for new Java programmers.
c. JavaFX has a built-in 3D, animation support, video and audio playback, and runs as a standalone application or from a browser.
d. JavaFX incorporates modern GUI technologies to enable you to develop rich Internet applications.

a. JavaFX provides a multi-touch support for touch-enabled devices such as tablets and smart phones.
b. JavaFX is much simpler to learn and use for new Java programmers.
c. JavaFX has a built-in 3D, animation support, video and audio playback, and runs as a standalone application or from a browser.
d. JavaFX incorporates modern GUI technologies to enable you to develop rich Internet applications.

2
New cards

Every JavaFX main class ____. Select all that apply.

a. extends javafx.application.Application

b. implements javafx.application.Application

c. overrides start(Stage s) method

d. overrides start() method

extends javafx.application.Application
overrides start(Stage s) method

3
New cards

Which of the following statements are true? Select all that apply.

a. You can have multiple stages displayed in a JavaFX program.
b. A scene is placed in the stage using the setScene method
c. A scene is placed in the stage using the addScene method
d. A primary stage is automatically created when a JavaFX main class is launched.
e. A stage is displayed by invoking the show() method on the stage.

a. You can have multiple stages displayed in a JavaFX program.
b. A scene is placed in the stage using the setScene method
d. A primary stage is automatically created when a JavaFX main class is launched.
e. A stage is displayed by invoking the show() method on the stage.

4
New cards

What is the output of the following JavaFX program?

import javafx.application.Application;
import javafx.stage.Stage;

public class Test extends Application {
public Test() {
System.out.println("Test constructor is invoked.");
}

@Override
// Override the start method in the Application class
public void start(Stage primaryStage) {
System.out.println("start method is invoked.");
}

public static void main(String[] args) {
System.out.println("launch application.");
Application.launch(args);
}
}

a. launch application. start method is invoked. Test constructor is invoked.
b. launch application. Test constructor is invoked. start method is invoked.
c. launch application. start method is invoked.
d. start method is invoked. Test constructor is invoked.
e. Test constructor is invoked. start method is invoked.

b. launch application. Test constructor is invoked. start method is invoked.

5
New cards

Which of the following statements are true? Select all that apply.

a. A Pane is a Node.
b. A Stage is a Node.
c. A Shape is a Node.
d. A Control is a Node.
e. A Scene is a Node.

a. A Pane is a Node.
c. A Shape is a Node.
d. A Control is a Node.

6
New cards

Which of the following statements is true?

a. A Node can be placed in a Scene.
b. A Shape can be placed in a Control.
c. A Node can be placed in a Pane.
d. A Pane can be placed in a Control.

c. A Node can be placed in a Pane.

7
New cards

Which of the following statements are correct? Select all that apply.

a. new Scene(new Circle());
b. new Scene(new ImageView());
c. new Scene(new Button("OK"));
d. new Scene(new Pane());

c. new Scene(new Button("OK"));
d. new Scene(new Pane());

8
New cards

To add a circle object into a pane, use ____. Select all that apply.

a. pane.add(circle);
b. pane.getChildren().add(circle);
c. pane.addAll(circle);
d. pane.getChildren().addAll(circle);

b. pane.getChildren().add(circle);
d. pane.getChildren().addAll(circle);

9
New cards

Which of the following statements are correct? Select all that apply.

a. Every subclass of Node has a no-arg constructor.
b. Circle is a subclass of Node.
c. Button is a subclass of Node.
d. Pane is a subclass of Node.
e. Scene is a subclass on Node.

a. Every subclass of Node has a no-arg constructor.
b. Circle is a subclass of Node.
c. Button is a subclass of Node.
d. Pane is a subclass of Node.

10
New cards

Which of the following statements correctly sets the fill color of circle to black? Select all that apply.

a. circle.setStyle("-fx-fill-color: black");
b. circle.setFill(Color.BLACK);
c. circle.setStyle("-fx-fill: black");
d. circle.setStyle("fill: black");
e. circle.setFill(Color.black);

b. circle.setFill(Color.BLACK);
c. circle.setStyle("-fx-fill: black");

11
New cards

Which of the following statements correctly rotates the button 45 degrees counterclockwise? Select all that apply.

a. button.setRotate(-45);
b. button.setRotate(45);
c. button.setRotate(360 - 45);
d. button.setRotate(Math.toRadians(45));

a. button.setRotate(-45);
c. button.setRotate(360 - 45);

12
New cards

Which of the following statements correctly creates a Color object? Select all that apply.

a. new Color(0.3, 0.5, 0.5);
b. Color.color(0.3, 0.5, 0.5);
c. new Color(3, 5, 5, 1);
d. Color.color(0.3, 0.5, 0.5, 0.1);
e. new Color(0.3, 0.5, 0.5, 0.1);

b. Color.color(0.3, 0.5, 0.5);
d. Color.color(0.3, 0.5, 0.5, 0.1);
e. new Color(0.3, 0.5, 0.5, 0.1);

13
New cards

Which of the following statements correctly creates a Font object? Select all that apply.

a. Font.font("Times", FontWeight.NORMAL, 34);
b. new Font(34);
c. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);
d. new Font("Times", 34);
e. Font.font("Times", 34);

a. Font.font("Times", FontWeight.NORMAL, 34);
b. new Font(34);
c. Font.font("Times", FontWeight.NORMAL, FontPosture.ITALIC, 34);
d. new Font("Times", 34);
e. Font.font("Times", 34);

14
New cards

Which of the following statements are correct? Select all that apply.

a. A Color object is immutable.
b. You cannot change the contents in a Color object once it is created.
c. You cannot change the contents in a Font object once it is created.
d. A Font object is immutable.

a. A Color object is immutable.
b. You cannot change the contents in a Color object once it is created.
c. You cannot change the contents in a Font object once it is created.
d. A Font object is immutable.

15
New cards

Which of the following statements correctly creates an ImageView object? Select all that apply.

a. new ImageView("image/us.gif");
b. new ImageView("");
c. new ImageView(new Image("image/us.gif"));
d. new ImageView(new Image(""));

a. new ImageView("image/us.gif");
b. new ImageView("");
c. new ImageView(new Image("image/us.gif"));
d. new ImageView(new Image(""));

16
New cards

Analyze the following code:

various parts of code removed due to character limit

public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {

// Create a pane to hold the image views
Pane pane = new HBox(10);
pane.setPadding(new Insets(5, 5, 5, 5));
Image image = new image("www.cs.armstrong.edu/liang/image/us.gif");
pane.getChildren().addAll(new ImageView(image), new ImageView(image));

// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("ShowImage");
primaryStage.setScene(scene);
primaryStage.show();

a. The image object cannot be shared by two ImageViews.
b. The addAll method needs to be replaced by the add method.
c. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new Image("").
d. The program runs fine and displays two images.

c. new Image("www.cs.armstrong.edu/liang/image/us.gif") must be replaced by new Image("").

17
New cards

A JavaFX action event handler is an instance of ___.

a. ActionEvent

b. EventHandler

c. EventHandler<ActionEvent>

d. Action

c. EventHandler<ActionEvent>

18
New cards

A JavaFX action event handler contains a method ___.

a. public void handle(ActionEvent e)
b. public void actionPerformed(ActionEvent e)
c. public void actionPerformed(Event e)
d. public void handle(Event e)

a. public void handle(ActionEvent e)

19
New cards

A JavaFX event handler for event type T is an instance of ___.

a. Action
b. ActionEvent
c. EventHandler<T>
d. EventHandler

c. EventHandler<T>

20
New cards

Which of the following are the classes in JavaFX for representing an event? Select all that apply.

a. MouseEvent
b. ActionEvent
c. WindowEvent
d. KeyEvent

a. MouseEvent
b. ActionEvent
c. WindowEvent
d. KeyEvent

21
New cards

To register a source for an action event with a handler, use ___.

a. source.addAction(handler)
b. source.setOnAction(handler)
c. source.setActionHandler(handler)
d. source.addOnAction(handler)

b. source.setOnAction(handler)

22
New cards

Which of the following statements are true? Select all that apply.

a. A source object fires an event.
b. A handler is registered with the source object for processing the event.
c. Any object such a String object can fire an event.
d. A handler object fires an event.

a. A source object fires an event.
b. A handler is registered with the source object for processing the event.

23
New cards

Which of the following statements are true? Select all that apply.

a. A Button can fire a KeyEvent.
b. A TextField can fire an ActionEvent.
c. A Button can fire a MouseEvent.
d. A Button can fire an ActionEvent.

a. A Button can fire a KeyEvent.
b. A TextField can fire an ActionEvent.
c. A Button can fire a MouseEvent.
d. A Button can fire an ActionEvent.

24
New cards

Which of the following statements are true? Select all that apply.

a. A Node can fire an ActionEvent.
b. A Node can fire a KeyEvent.
c. A Noden can fire a MouseEvent.
d. A Scene can fire a MouseEvent.

a. A Node can fire an ActionEvent.
b. A Node can fire a KeyEvent.
c. A Noden can fire a MouseEvent.
d. A Scene can fire a MouseEvent.

25
New cards

Which of the following statements are true? Select all that apply.

a. A Shape can fire an ActionEvent.
b. A Circle is a Shape.
c. A Shape can fire a KeyEvent.
d. A Text is a Shape.
e. A Shape can fire a MouseEvent.

b. A Circle is a Shape.
c. A Shape can fire a KeyEvent.
d. A Text is a Shape.
e. A Shape can fire a MouseEvent.

26
New cards

Which of the following statements are true? Select all that apply.

a. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class.
b. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class.
c. Inner classes can make programs simple and concise.
d. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class.

a. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class.
b. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class.
c. Inner classes can make programs simple and concise.
d. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class.

27
New cards

Suppose A is an inner class in Test. A is compiled into a file named ___.

a. Test$A.class
b. Test&A.class
c. A$Test.class
d. A.class

a. Test$A.class

28
New cards

Which of the following statements are true? Select all that apply.

a. An anonymous inner class must implement all the abstract methods in the superclass or in the interface.
b. An anonymous inner class is compiled into a class named OuterClassName$n.class.
c. An anonymous inner class always uses the no-arg constructor from its superclass to create an instance. If an anonymous inner class implements an interface, the constructor is Object().
d. An anonymous inner class is an inner class without a name.
e. An anonymous inner class must always extend a superclass or implement an interface, but it cannot have an explicit extends or implements clause.

a. An anonymous inner class must implement all the abstract methods in the superclass or in the interface.
b. An anonymous inner class is compiled into a class named OuterClassName$n.class.
c. An anonymous inner class always uses the no-arg constructor from its superclass to create an instance. If an anonymous inner class implements an interface, the constructor is Object().
d. An anonymous inner class is an inner class without a name.
e. An anonymous inner class must always extend a superclass or implement an interface, but it cannot have an explicit extends or implements clause.

29
New cards

Suppose A is an anonymous inner class in Test. A is compiled into a file named ___.

a. A.class
b. A$Test.class
c. Test$1.class
d. Test&1.class
e. Test$A.class

c. Test$1.class

30
New cards

Analyze the following code.

import javafx.application.Application;
javafx.event.ActionEvent;
javafx.event.EventHandler;
javafx.scene.Scene;
javafx.scene.control.Button;
javafx.stage.Stage;

public class Test extends Application {
@Override
public void start(Stage primaryStage) {
Button btOK = new Button("OK");
btOK.setOnAction(new EventHandler() {
public void handle(ActionEvent e) {
System.out.println("The OK button is clicked");
}
});
SOME CODE OMITTED

a. The program has a runtime error because no handlers are registered with btOK.
b. The handle method is not executed when you click the OK button, because no handler is registered with btOK.
c. The message "The OK button is clicked" is displayed when you click the OK button.
d. The program has a compile error because no handlers are registered with btOK.

c. The message "The OK button is clicked" is displayed when you click the OK button.

31
New cards

Analyze the following code. Select all that apply.

import javafx.application.Application;
.event.ActionEvent;
.event.EventHandler;
… (omitted)

public class Test extends Application {
@Override
public void start(Stage primaryStage) {
Button btOK = new Button("OK");
Button btCancel = new Button("Cancel");
EventHandler handler = new EventHandler() {
public void handle(ActionEvent e) {
System.out.println("The OK button is clicked");
}};

btOK.setOnAction(handler);
btCancel.setOnAction(handler);
SOME CODE OMITTED

a. When clicking either button, the program displays The OK button is clicked twice.
b. The program has a runtime error, because the handler is registered with more than one source.
c. When clicking the Cancel button, the program displays The OK button is clicked.
d. When clicking the OK button, the program displays The OK button is clicked.

c. When clicking the Cancel button, the program displays The OK button is clicked.
d. When clicking the OK button, the program displays The OK button is clicked.

32
New cards

Analyze the following code.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class Test extends Application {
@Override
public void start(Stage primaryStage) {
Button btOK = new Button("OK");
btOK.setOnAction(e -> System.out.println("OK 1"));
btOK.setOnAction(e -> System.out.println("OK 2"));

Scene scene = new Scene(btOK, 200, 250);
primaryStage.setTitle("MyJavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
SOME CODE OMITTED

a. When clicking the button, the program displays OK1.
b. When clicking the button, the program displays OK2.
c. When clicking the button, the program displays OK1 OK2.
d. The program has a compile error, because the setOnAction method is invoked twice.

b. When clicking the button, the program displays OK2.

33
New cards

Which of the following code correctly registers a handler with a button btOK? Select all that apply.

a. btOK.setOnAction((ActionEvent e) ->; System.out.println("Handle the event"));
b. btOK.setOnAction(e ->; {System.out.println("Handle the event");});
c. btOK.setOnAction((e) ->; System.out.println("Handle the event"););
d. btOK.setOnAction(e ->; System.out.println("Handle the event"));

a. btOK.setOnAction((ActionEvent e) ->; System.out.println("Handle the event"));
b. btOK.setOnAction(e ->; {System.out.println("Handle the event");});
c. btOK.setOnAction((e) ->; System.out.println("Handle the event"););
d. btOK.setOnAction(e ->; System.out.println("Handle the event"));

34
New cards

Fill in the code below in the underline:

public class Test {
public static void main(String[] args) {
Test test = new Test();
test.setAction(____________);
}

public void setAction(T1 t) {
t.m();
}
}
interface T1 {
public void m();
}

a. (e) ->; {System.out.print("Action 1! ")}
b. () ->; System.out.print("Action 1! ")
c. (e) ->; System.out.print("Action 1! ")
d. System.out.print("Action 1! ")

b. () ->; System.out.print("Action 1! ")

35
New cards

Fill in the code below in the underline. Select all that apply.

public class Test {
public static void main(String[] args) {
Test test = new Test();
test.setAction2(____________);
}

public void setAction2(T2 t) {
t.m(4.5);
}
}

interface T2 {
public void m(Double d);
}

a. e ->; System.out.print(e)
b. () ->; System.out.print(e)
c. (e) ->; System.out.print(e)
d. (e) ->; {System.out.print(e);}

a. e ->; System.out.print(e)
c. (e) ->; System.out.print(e)
d. (e) ->; {System.out.print(e);}

36
New cards

Fill in the code below in the underline. Select all that apply.

public class Test {
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.setAction3(____________));
}

public double setAction3(T3 t) {
return t.m(5.5);
}
}

interface T3 {
public double m(Double d);
}

a. e ->; e * 2
b. (e) ->; {e * 2;}
c. (e) ->; e * 2
d. () ->; e * 2

a. e ->; e * 2
c. (e) ->; e * 2

37
New cards

Analyze the following code. Select all that apply.

public class Test {
public static void main(String[] args) {
Test test = new Test();
test.setAction(() -> System.out.print("Action 1! "));
}

public void setAction(T t) {
t.m1();
}
}

interface T {
public void m1();
public void m2();
}

a. The program displays Action 1.
b. The program has a runtime error because T is not a functional interface. T contains multiple methods.
c. The program has a compile error because T is not a functional interface. T contains multiple methods.
d. The program would work if you delete the method m2 from the interface T.

c. The program has a compile error because T is not a functional interface. T contains multiple methods.
d. The program would work if you delete the method m2 from the interface T.

38
New cards

To handle the mouse click event on a pane p, register the handler with p using ___.

a. p.setOnMouseClicked(handler);
b. p.setOnMouseDragged(handler);
c. p.setOnMouseReleased(handler);
d. p.setOnMousePressed(handler);

a. p.setOnMouseClicked(handler);

39
New cards

Fill in the code to display the mouse point location when the mouse is pressed in the pane.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Test extends Application {
@Override
public void start(Stage primaryStage) {
Pane pane = new Pane();

____________________

Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle("Test");
primaryStage.setScene(scene);
primaryStage.show();
}
SOME CODE OMITTED

a. pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY()));
b. pane.setOnMouseDragged((e) -> System.out.println(e.getX() + ", " + e.getY()));
c. pane.setOnMouseReleased(e -> {System.out.println(e.getX() + ", " + e.getY())});
d. pane.setOnMouseClicked((e) -> System.out.println(e.getX() + ", " + e.getY()));

a. pane.setOnMousePressed(e -> System.out.println(e.getX() + ", " + e.getY()));

40
New cards

Fill in the code to display the key pressed in the text. Select all that apply.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Test extends Application {
@Override
public void start(Stage primaryStage) {
Pane pane = new Pane();
Text text = new Text(20, 20, "Welcome");
pane.getChildren().add(text);
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle("Test")
primaryStage.setScene(scene);
primaryStage.show();

text.setFocusTraversable(true);
text.setOnKeyPressed(_);
}
SOME CODE OMITTED

a. (e) ->; text.setText(e.getText())
b. () ->; text.setText(e.getText())
c. e ->; {text.setText(e.getText());}
d. e ->; text.setText(e.getText())

a. (e) ->; text.setText(e.getText())
c. e ->; {text.setText(e.getText());}
d. e ->; text.setText(e.getText())

41
New cards

To handle the key pressed event on a pane p, register the handler with p using ___.

a. p.setOnKeyReleased(handler);
b. p.setOnKeyTyped(handler);
c. p.setOnKeyClicked(handler);
d. p.setOnKeyPressed(handler);

d. p.setOnKeyPressed(handler);

42
New cards

Suppose the following program displays a pane in the stage. What is the output if the user presses the key for letter B?

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Test1 extends Application {
@Override
public void start(Stage primaryStage) {
Pane pane = new Pane();
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle("MyJavaFX");
primaryStage.setScene(scene);
primaryStage.show();

pane.requestFocus();
pane.setOnKeyPressed(e ->
System.out.print("Key pressed " + e.getCode() + " "));
pane.setOnKeyTyped(e ->
System.out.println("Key typed " + e.getCode()));
}
SOME CODE OMITTED

a. Key pressed B Key typed
b. Key pressed B Key typed UNDEFINED
c. Key pressed B
d. Key typed UNDEFINED

b. Key pressed B Key typed UNDEFINED

43
New cards

Suppose the following program displays a pane in the stage. What is the output if the user presses the DOWN arrow key?

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Test1 extends Application {
@Override
public void start(Stage primaryStage) {

Pane pane = new Pane();
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle("MyJavaFX");
primaryStage.setScene(scene);
primaryStage.show();

pane.requestFocus();
pane.setOnKeyPressed(e ->
System.out.print("Key pressed " + e.getCode() + " "));
pane.setOnKeyTyped(e ->
System.out.println("Key typed " + e.getCode()));
}
SOME CODE OMITTED

a. Key pressed DOWN
b. Key pressed DOWN Key typed
c. Key typed UNDEFINED
d. Key pressed DOWN Key typed UNDEFINED

a. Key pressed DOWN

44
New cards

Which of the following methods is not defined in the Animation class?

a. play()
b. stop()
c. pause()
d. resume()

d. resume()

45
New cards

The properties ___ are defined in the Animation class. Select all that apply.

a. rate
b. autoReverse
c. status
d. cycleCount

a. rate
b. autoReverse
c. status
d. cycleCount

46
New cards

The properties ___ are defined in the PathTransition class. Select all that apply.

a. duration
b. orientation
c. node
d. path

a. duration
b. orientation
c. node
d. path

47
New cards

The properties ___ are defined in the FadeTransition class. Select all that apply.

a. fromValue
b. duration
c. toValue
d. node
e. byValue

a. fromValue
b. duration
c. toValue
d. node
e. byValue

48
New cards

___ is a subclass of Animation. Select all that apply.


a. Duration
b. PathTransition
c. FadeTransition
d. Timeline

b. PathTransition
c. FadeTransition
d. Timeline