Handler Flashcards

1
Q

Explain every line of code:
public class HandleEvent extends Application {

public void start(Stage primaryStage) {
OKHandlerClass handler1 = new OKHandlerClass();
btOK.setOnAction(handler1);
CancelHandlerClass handler2 = new CancelHandlerClass();
btCancel.setOnAction(handler2);

primaryStage.show(); // Display the stage
}
}
class OKHandlerClass implements EventHandler<ActionEvent> {
@Override
public void handle(ActionEvent e) {
System.out.println("OK button clicked");
}
}</ActionEvent>

A
  1. The public voids start codeblock will display the the GUI to the user
  2. The 2 Handler functions are being used, one(OKHandlerClass) for if the user hits the OK button, the other(CancelHandlerClass) if they click on Cancel. Using btOK.setOnAction(handler1), the button will be active.
  3. When buttons are clicked the handle method in each handler class is activated.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the hierarchy of the Event classes?

-EventObject
-Event
-ActionEvent
-InputEvent
-MouseEvent
-KeyEvent
-WindowEvent

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Note event classes are in the javafx.event package

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly