Загрузка данных


package com.example.demo;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class HelloController {
    @FXML
    private TextField num1;
    @FXML
    private TextField num2;
    @FXML
    private Label resultLabel;

    @FXML
    protected void onPlusClick() { calculate('+'); }
    @FXML
    protected void onMinusClick() { calculate('-'); }
    @FXML
    protected void onMultClick() { calculate('*'); }
    @FXML
    protected void onDivClick() { calculate('/'); }

    private void calculate(char op) {
        try {
            double n1 = Double.parseDouble(num1.getText());
            double n2 = Double.parseDouble(num2.getText());
            double res = 0;

            if (op == '+') res = n1 + n2;
            else if (op == '-') res = n1 - n2;
            else if (op == '*') res = n1 * n2;
            else if (op == '/') res = n1 / n2;

            resultLabel.setText("Результат: " + res);
        } catch (NumberFormatException e) {
            resultLabel.setText("Ошибка: введите числа!");
        }
    }
}