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());