1
Name:_______________________
(150 minutes)
CSCI 1302 OO Programming
Armstrong Atlantic State University
Instructor: Dr. Y. Daniel Liang
I pledge by honor that I will not discuss this exam with anyone until my
instructor reviews the exam in the class.
Signed by ___________________ Date _____________________
Part I:
A. (2 pts)
Fill in the missing code in the following program.
import javafx.application.Application;
B. (2 pts)
Show the output of the following JavaFX program.
import javafx.application.Application;
2
C. (5 pt)
Which of following statements are correct?
1. You can create and display multiple stages in JavaFX.
D. (3 pt)
Write the code for the following:
1. Create a line with the end points (5.5, 54) and (0.2,
45).
3
Part II: Write Programs
1. (5 pts) The ClockPane class presented in Listing 14.24
4
2. (10 pts) Write a program that clicks the Refresh
button to display the four distinct random numbers
between 0 and 51, as shown in the following figure.
5
3. (15 pts) Write a program that draws a fixed rectangle
centered at (100, 60) with width 100 and height 40.
Whenever the mouse is moved, display a message
indicating whether the mouse point is inside the
6
Part III: Multiple Choice Questions: (1 pts each)
(Please circle your answers on paper first. After you
finish the test, enter your choices online to LiveLab. Log
in and click Take Instructor Assigned Quiz. Choose Quiz3.
You have 5 minutes to enter and submit the answers.)
1
What is the output of the following code?
import javafx.beans.property.IntegerProperty;
A. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3
B. d1 is 2 and d2 is 2, d1 is 2 and d2 is 3
C. d1 is 1 and d2 is 2, d1 is 3 and d2 is 3
D. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3
#
2
Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
7
class
public void start(Stage primaryStage) {
// Create a pane to hold the image views
Pane pane = new HBox(10);
/**
* 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);
}
}
#
3
To place a node in the left of a BorderPane p, use
___________.
A. p.left(node);
B. p.setLeft(node);
C. p.setEast(node);
D. p.placeLeft(node);
8
#
4
To place two nodes node1 and node2 in a HBox p, use
___________.
#
5
Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Circle;
public class Test extends Application {
@Override // Override the start method in the Application
class
public void start(Stage primaryStage) {
HBox pane = new HBox(5);
Circle circle = new Circle(50, 200, 200);
pane.getChildren().addAll(circle);
9
public static void main(String[] args) {
launch(args);
}
}
A. The program has a compile error since the circle is added to a
pane twice.
#
6
To remove two nodes node1 and node2 from a pane, use ______.
A. pane.removeAll(node1, node2);
B. pane.getChildren().remove(node1, node2);
C. pane.getChildren().removeAll(node1, node2);
D. pane.remove(node1, node2);
#
7
Analyze the following code.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
10
/**
* 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. When clicking the button, the program displays OK2.
#
8
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 classes omitted
public class Test1 extends Application {
@Override
public void start(Stage primaryStage) {
// Code to create and display pane omitted
Pane pane = new Pane();
Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle(“MyJavaFX”); // Set the stage
title
primaryStage.setScene(scene); // Place the scene in the
stage
primaryStage.show(); // Display the stage
11
System.out.println(“Key typed ” + e.getCode()));
}
/**
* 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. Key pressed B Key typed UNDEFINED
B. Key typed UNDEFINED
#
9
Suppose A is an anonymous inner class in Test. A is compiled
into a file named _________.
A. Test$A.class
B. A$Test.class
C. A.class
D. Test$1.class
E. Test&1.class
#
10
Fill in the code below in the underline:
public class Test {
12
public void m();
}
A. (e) > {System.out.print(“Action 1! “)}
B. (e) > System.out.print(“Action 1! “)
C. () > System.out.print(“Action 1! “)
D. System.out.print(“Action 1! “)
#
11
To handle the mouse click event on a pane p, register the
handler with p using ______.
#
12
A JavaFX action event handler is an instance of _______.
A. EventHandler<ActionEvent>
B. ActionEvent
C. EventHandler
D. Action
#
13
Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
13
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);
/**
* 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 are displayed with the same text “Java”.
B. Three buttons are displayed with the same text “Java”.
C. One button is displayed with the text “Java”.
D. Four buttons are displayed with the same text “Java”.
#
14
The method __________ gets the contents of the text field
tf.
Please double check your answer before clicking the Submit
button. Whatever submitted to LiveLab is FINAL and counted
for your grade.
Have you submitted your answer to LiveLib? ______________