Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What is wrong in the below code??? A. public class Test extends Application {

ID: 3688284 • Letter: 1

Question

1. What is wrong in the below 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
}
}

Explanation / Answer

B.
public class Test extends Application {
   public void start(Stage stage) {
       Button btOK = new Button("OK");
       btOK.setOnAction(new EventHandler<ActionEvent>(){ //modified
               public void handle(ActionEvent e) {
                   System.out.println
                   (e.getSource());
               }
           }); // modified
   }
}