mirror of
https://github.com/DanilaFe/abacus
synced 2024-09-07 00:03:05 -07:00
Link up the evaluation and the UI buttons.
This commit is contained in:
parent
41395f09f9
commit
8c935983b2
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
|
||||
<?import javafx.scene.text.Text?>
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.nwapw.abacus.fx.AbacusController">
|
||||
|
@ -15,9 +16,10 @@
|
|||
<VBox>
|
||||
<ScrollPane prefHeight="50" vbarPolicy="NEVER">
|
||||
<padding><Insets top="10" bottom="10" left="10" right="10"/></padding>
|
||||
<Text fx:id="outputText"/>
|
||||
</ScrollPane>
|
||||
<TextField text="Input"/>
|
||||
<Button text="Calculate" maxWidth="Infinity"/>
|
||||
<TextField fx:id="inputField" onAction="#performCalculation"/>
|
||||
<Button fx:id="inputButton" text="Calculate" maxWidth="Infinity" onAction="#performCalculation"/>
|
||||
</VBox>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
|
@ -25,5 +27,5 @@
|
|||
<Tab text="Settings" closable="false"/>
|
||||
</TabPane>
|
||||
</center>
|
||||
|
||||
|
||||
</BorderPane>
|
||||
|
|
Loading…
Reference in New Issue
Block a user