Design a 16button integer calculator that supports addition
Design a 16-button integer calculator that supports addition, subtraction, multiplication, and division. Use JavaFX to build your project. It should function the same way as a standard calculator except it only handles integers. Your interface should be similar to that below.
Calculator
Hints:
Download JavaFX Scene Builder from the Oracle website. It is not, I repeat NOT supported anymore, but it is a great way to get started building screen mockups. The image above was produced using Scene Builder. In addition, it actually does generate screen layout code if you want to use it in your program. Refer to the link in the lab example above for more information about installing and using Scene Builder.
There are multiple ways you can configure your program to work correctly. I suggest that you keep things simple. Here are the 3 possible scenarios. If your program can perform in this manner, it will be considered correct.
Solution
Program:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage,
public class Calculator extends Application. {
double number1 = 0;
double number2 = 0;
double answer = 0;
@Override
public void start(Stage primaryStage) throws Exception {
HBox numberPane = new HBox();
numberPane.setSpacing(10);
numberPane.setAlignment(Pos.CENTER);
Label lblNumber1 = new Label(\"Number 1:\");
TextField tfNumber1 = new TextField();
Label lblNumber2 = new Label(\"Number 2:\");
TextField tfNumber2 = new TextField();
Label lblResult = new Label(\"Result :\");
TextField tfResult = new TextField();
numberPane.getChildren().addAll(
lblNumber1, tfNumber1,
lblNumber2, tfNumber2,
lblResult, tfResult);
Button btAdd = new Button(\"Add\");
btAdd.setOnAction(e -> {
answer = Double.parseDouble(tfNumber1.getText()) + Double.parseDouble(tfNumber2.getText());
tfResult.setText(answer + \"\");
});
Button btSubtract = new Button(\"subtract\");
btSubtract.setOnAction(e -> {
answer = Double.parseDouble(tfNumber1.getText()) - Double.parseDouble(tfNumber2.getText());
tfResult.setText(answer + \"\");
});
Button btMultiply = new Button(\"Multiply\");
btMultiply.setOnAction(e -> {
answer = Double.parseDouble(tfNumber1.getText()) * Double.parseDouble(tfNumber2.getText());
tfResult.setText(answer + \"\");
});
Button btDivide = new Button(\"Divide\");
btDivide.setOnAction(e -> {
answer = Double.parseDouble(tfNumber1.getText()) / Double.parseDouble(tfNumber2.getText());
tfResult.setText(answer + \"\");
});
HBox operatorsPane = new HBox();
operatorsPane.setSpacing(10);
operatorsPane.setAlignment(Pos.CENTER);
operatorsPane.getChildren().addAll(btAdd, btSubtract, btMultiply, btDivide);
BorderPane borderPane = new BorderPane(numberPane);
BorderPane.setMargin(numberPane, new Insets(10, 10, 10, 10));
borderPane.setBottom(operatorsPane);
BorderPane.setMargin(operatorsPane, new Insets(10, 10, 10, 10));
primaryStage.setScene(new Scene(borderPane, borderPane.getPrefWidth(),borderPane.getPrefWidth()));
primaryStage.setTitle(\"Simple calculator\");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args)}}


