This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code.import javafx.application.Application;import ... (Read 28 times)

rachel9

  • Sr. Member
  • ****
  • Posts: 495
Analyze the following code.

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

public class Test extends Application {
@Override // Override the start method in the Application class
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);

HBox pane = new HBox(5);
pane.getChildren().addAll(btOK, btCancel);

Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle("Test"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}

/**
* 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);
}
}

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


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by rachel9 on May 6, 2020

bbburns21

  • Sr. Member
  • ****
  • Posts: 336
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




rachel9

  • Member
  • Posts: 495
Reply 2 on: May 6, 2020
Great answer, keep it coming :)


miss.ashley

  • Member
  • Posts: 371
Reply 3 on: Yesterday
Gracias!

 

Did you know?

Though methadone is often used to treat dependency on other opioids, the drug itself can be abused. Crushing or snorting methadone can achieve the opiate "rush" desired by addicts. Improper use such as these can lead to a dangerous dependency on methadone. This drug now accounts for nearly one-third of opioid-related deaths.

Did you know?

Each year in the United States, there are approximately six million pregnancies. This means that at any one time, about 4% of women in the United States are pregnant.

Did you know?

People with high total cholesterol have about two times the risk for heart disease as people with ideal levels.

Did you know?

The U.S. Preventive Services Task Force recommends that all women age 65 years of age or older should be screened with bone densitometry.

Did you know?

Astigmatism is the most common vision problem. It may accompany nearsightedness or farsightedness. It is usually caused by an irregularly shaped cornea, but sometimes it is the result of an irregularly shaped lens. Either type can be corrected by eyeglasses, contact lenses, or refractive surgery.

For a complete list of videos, visit our video library