From 6da9aef3ad26e8c5807ab8566c4892e200234d86 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Wed, 18 Nov 2020 16:37:13 +0300 Subject: [PATCH] lab-05: Fixed NullEx and noted bug --- lab-05/src/CalculatorPane.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lab-05/src/CalculatorPane.java b/lab-05/src/CalculatorPane.java index 8f9676d..b61e24a 100644 --- a/lab-05/src/CalculatorPane.java +++ b/lab-05/src/CalculatorPane.java @@ -21,7 +21,6 @@ public class CalculatorPane extends VBox implements EventHandler { public CalculatorPane(){ - constructButtons(); setSpacing(15); setPadding(new Insets(10)); ioField = new TextField(); @@ -29,14 +28,14 @@ public class CalculatorPane extends VBox implements EventHandler { ioField.setEditable(false); ioField.setText(""); ioField.setPrefHeight(15); - - + constructButtons(); } private void calculateAndDisplay() { if (subtracting) { display(String.valueOf(firstOperand - Integer.parseInt(ioField.getText()))); + subtracting = false; } else display(String.valueOf(firstOperand+Integer.parseInt(ioField.getText()))); } @@ -61,6 +60,7 @@ public class CalculatorPane extends VBox implements EventHandler { ioField.setText(result); } + //Handle all number buttons @Override public void handle(MouseEvent mouseEvent) { int pressedBtn = 0; @@ -75,6 +75,7 @@ public class CalculatorPane extends VBox implements EventHandler { ioField.setText(ioField.getText()+ pressedBtn); } else { + //TODO: removes prev digit. (cant place 2 or more digits for second operand. ioField.setText(String.valueOf(pressedBtn)); } } @@ -100,6 +101,7 @@ public class CalculatorPane extends VBox implements EventHandler { btn.setOnMouseClicked(this); } + //set Event handlers for op buttons btnList[Buttons.CLEAR].setOnMouseClicked(e-> clear()); btnList[Buttons.PLUS].setOnMouseClicked(e -> add()); btnList[Buttons.MINUS].setOnMouseClicked(e -> subtract());