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

Author Question: Analyze the following code.import javafx.application.Application;import ... (Read 27 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
Wow, this really help


abro1885

  • Member
  • Posts: 337
Reply 3 on: Yesterday
Great answer, keep it coming :)

 

Did you know?

Signs and symptoms that may signify an eye tumor include general blurred vision, bulging eye(s), double vision, a sensation of a foreign body in the eye(s), iris defects, limited ability to move the eyelid(s), limited ability to move the eye(s), pain or discomfort in or around the eyes or eyelids, red or pink eyes, white or cloud spots on the eye(s), colored spots on the eyelid(s), swelling around the eyes, swollen eyelid(s), and general vision loss.

Did you know?

Stevens-Johnson syndrome and Toxic Epidermal Necrolysis syndrome are life-threatening reactions that can result in death. Complications include permanent blindness, dry-eye syndrome, lung damage, photophobia, asthma, chronic obstructive pulmonary disease, permanent loss of nail beds, scarring of mucous membranes, arthritis, and chronic fatigue syndrome. Many patients' pores scar shut, causing them to retain heat.

Did you know?

Nearly all drugs pass into human breast milk. How often a drug is taken influences the amount of drug that will pass into the milk. Medications taken 30 to 60 minutes before breastfeeding are likely to be at peak blood levels when the baby is nursing.

Did you know?

According to the FDA, adverse drug events harmed or killed approximately 1,200,000 people in the United States in the year 2015.

Did you know?

The first oncogene was discovered in 1970 and was termed SRC (pronounced "SARK").

For a complete list of videos, visit our video library