Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JavaFX) Add event handling to the buttons btAdd, btSubbtract , btMutlitply, and btDivide and place result in tfResult. Attach your .java file for a response

(JavaFX) Add event handling to the buttons btAdd, btSubbtract , btMutlitply, and btDivide and place result in tfResult. Attach your .java file for a response which contains the code presented here and your modificiations. (20 points)

//You will need to add the necessary imports.

public class Midterm_2 extends Application {

@Override

public void start(Stage primaryStage) {

HBox pane = new HBox();

pane.setAlignment(Pos.CENTER);

TextField tfNumber1 = new TextField();

TextField tfNumber2 = new TextField();

TextField tfResult = new TextField();

tfResult.setEditable(false);

tfNumber1.setPrefColumnCount(3);

tfNumber2.setPrefColumnCount(3);

tfResult.setPrefColumnCount(3);

pane.getChildren().addAll(new Label("Number 1: "), tfNumber1,

new Label("Number 2: "), tfNumber2, new Label("Result: "), tfResult);

// Create four buttons

HBox hBox = new HBox(5);

Button btAdd = new Button("Add");

Button btSubtract = new Button("Subtract");

Button btMultiply = new Button("Multiply");

Button btDivide = new Button("Divide");

hBox.setAlignment(Pos.CENTER);

hBox.getChildren().addAll(btAdd, btSubtract, btMultiply, btDivide);

BorderPane borderPane = new BorderPane();

borderPane.setCenter(pane);

borderPane.setBottom(hBox);

BorderPane.setAlignment(hBox, Pos.TOP_CENTER);

// Create a scene and place it in the stage

Scene scene = new Scene(borderPane, 250, 150);

primaryStage.setTitle("Calculator"); // Set the stage title

primaryStage.setScene(scene); // Place the scene in the stage

primaryStage.show(); // Display the stage

//put button handling code here. Anonymous inner classes work nicely!

}//end start

public static void main(String[] args) {

launch(args);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started