Question
I am currently working on a calculator with Scene Builder and Spring Tool Suite and I am currently missing some functions for the following buttons:
I am currently working on a calculator with Scene Builder and Spring Tool Suite and I am currently missing some functions for the following buttons:
Multiplication, division, subtraction, and clear window, could you please show me how to make these buttons work by adding the missing function from below, thanks?
JAVA code:
package application;
import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.TextField;
public class CalController {
double first, second, result;//created to show the first and second number added to the text field and its result. int oper;//this operator was created for plus, minus, division... @FXML private TextField txtField;
@FXML private Button four;
@FXML private Button five;
@FXML private Button plus;
@FXML private Button equal;
@FXML private Button one;
@FXML private Button two;
@FXML private Button three;
@FXML private Button subtraction;
@FXML private Button multiplication;
@FXML private Button division;
@FXML private Button six;
@FXML private Button zero;
@FXML private Button seven;
@FXML private Button eight;
@FXML private Button nine;
@FXML private Button clear;
@FXML void additionFuction(ActionEvent event) { String value= ((Button) event.getSource()).getText(); first= Double.parseDouble(txtField.getText()); txtField.setText(""); }
@FXML void clearWindow(ActionEvent event) {
}
@FXML void divisionFuction(ActionEvent event) { }
@FXML void equalFuction(ActionEvent event) {
second= Double.parseDouble(txtField.getText()); result= first+second; txtField.setText(Double.toString(result)); }
@FXML void handle(ActionEvent event) { String value= ((Button) event.getSource()).getText(); txtField.setText(txtField.getText()+value); }
@FXML void multiplicationFuction(ActionEvent event) {
} @FXML void subtractionFuction(ActionEvent event) { }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started