Due to the print book page limit, we cannot inlcude all good CheckPoint questions in the physical book. The CheckPoint on this Website may contain extra questions not printed in the book. The questions in some sections may have been reordered as a result. Nevertheless, it is easy to find the CheckPoint questions in the book on this Website. Please send suggestions and errata to Dr. Liang at y.daniel.liang@gmail.com. Indicate the book, edition, and question number in your email. Thanks!

Chapter 15 Check Point Questions

Section 15.2
15.2.1
What is an event source object? What is an event object? Describe the relationship between an event source object and an event object.
15.2.2
Can a button fire a MouseEvent? Can a button fire a KeyEvent? Can a button fire an ActionEvent?
Section 15.3
15.3.1
Why must a handler be an instance of an appropriate handler interface?
15.3.2
Explain how to register a handler object and how to implement a handler interface.
15.3.3
What is the handler method for the EventHandler<ActionEvent> interface?
15.3.4
What is the registration method for a button to register an ActionEvent handler?
Section 15.4
15.4.1
Can an inner class be used in a class other than the class in which it nests?
15.4.2
Can the modifiers public, protected, private, and static be used for inner classes?
Section 15.5
15.5.1
If class A is an inner class in class B, what is the .class file for A? If class B contains two anonymous inner classes, what are the .class file names for these two classes?
15.5.2
What is wrong in the following code?
(a)
public class Test extends Application {
  public void start(Stage stage) {
    Button btOK = new Button("OK");
  }

  private class Handler implements    
      EventHandler<ActionEvent> {
    public void handle(Action e) {
      System.out.println(e.getSource());
    }
  }
}

(b)
public class Test extends Application {
  public void start(Stage stage) {
    Button btOK = new Button("OK");

    btOK.setOnAction(
    new EventHandler<ActionEvent> {
      public void handle(ActionEvent e) {
        System.out.println(e.getSource());
      }
    }  // Something missing here
  }
}
Section 15.6
15.6.1
What is a lambda expression? What is the benefit of using lambda expressions for event handling? What is the syntax of a lambda expression?
15.6.2
What is a functional interface? Why is a functional interface required for a lambda expression?
15.6.3
Replace the code in lines 5 and 6 in TestLambda.java using anonymous inner classes.
Section 15.8
15.8.1
What method do you use to get the mouse-point position for a mouse event?
15.8.2
What methods do you use to register a handler for a mouse pressed, released, clicked, entered, exited, moved and dragged event?
Section 15.9
15.9.1
What methods do you use to register handlers for key pressed, key released, and key typed events? In which classes are these methods defined? (See Table 15.1)
15.9.2
What method do you use to get the key character for a key-typed event? What method do you use to get the key code for a key-pressed or key-released event?
15.9.3
How do you set focus on a node so it can listen for key events?
15.9.4
If the following code is inserted in line 57 in Listing 15.9, what is the output if the user presses the key for letter A? What is the output if the user presses the UP arrow key?
circlePane.setOnKeyPressed(e -> 
  System.out.println("Key pressed " + e.getCode()));
circlePane.setOnKeyTyped(e -> 
  System.out.println("Key typeed " + e.getCode()));
Section 15.10
15.10.1
What would happen if you replace pane with scene or primaryStage in lines 31-32?
Section 15.11
15.11.1
How do you set the cycle count of an animation to infinite? How do you auto reverse an animation? How do you start, pause, and stop an animation?
15.11.2
Are PathTransition, FadeTransition, and Timeline a subtype of Animation?
15.11.3
How do you create a PathTransition? How do you create a FadeTransition? How do you create a Timeline?
15.11.4
How do you create a KeyFrame?
Section 15.12
15.12.1
How does the program make the ball moving?
15.12.2
How does the code in Listing 15.17 BallPane.java change the direction of the ball movement?
15.12.3
What does the program do when the mouse is pressed on the ball pane? What does the program do when the mouse is released on the ball pane?
15.12.4
If line 32 in Listing 15.18 BounceBall.java is not in the program, what would happen when you press the UP or the DOWN arrow key?
15.12.5
If line 23 is not in Listing 15.17, what would happen?
Section 15.13
15.13.1
What would happen if line 29 in Listing 15.19 is removed?
15.13.2
What would happen if map is replaced by scene in line 21 in Listing 15.19?
15.13.3
What would happen if map is replaced by primaryStage in line 21 in Listing 15.19?