From 8c935983b210218a075349223240fcaf51494c6b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 17:17:56 -0700 Subject: [PATCH] Link up the evaluation and the UI buttons. --- .../org/nwapw/abacus/fx/AbacusController.java | 34 +++++++++++++++++++ src/main/resources/abacus.fxml | 8 +++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index e5a5923..d21c034 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -1,10 +1,25 @@ package org.nwapw.abacus.fx; import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.text.Text; import org.nwapw.abacus.Abacus; +import org.nwapw.abacus.number.NumberInterface; +import org.nwapw.abacus.tree.TreeNode; public class AbacusController { + private static final String ERR_SYNTAX = "Syntax Error"; + private static final String ERR_EVAL = "Evaluation Error"; + + @FXML + private Text outputText; + @FXML + private TextField inputField; + @FXML + private Button inputButton; + private Abacus abacus; @FXML @@ -12,4 +27,23 @@ public class AbacusController { abacus = new Abacus(); } + @FXML + private void performCalculation(){ + inputButton.setDisable(true); + TreeNode constructedTree = abacus.parseString(inputField.getText()); + if(constructedTree == null){ + outputText.setText(ERR_SYNTAX); + inputButton.setDisable(false); + return; + } + NumberInterface evaluatedNumber = abacus.evaluateTree(constructedTree); + if(constructedTree == null){ + outputText.setText(ERR_EVAL); + inputButton.setDisable(false); + return; + } + inputButton.setDisable(false); + outputText.setText(evaluatedNumber.toString()); + } + } diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 9883d94..ee4a28f 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -4,6 +4,7 @@ + @@ -15,9 +16,10 @@ + - -