Fixed NullEx and noted bug
This commit is contained in:
HeshamTB 2020-11-18 16:37:13 +03:00
parent c7147ee9da
commit 6da9aef3ad
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -21,7 +21,6 @@ public class CalculatorPane extends VBox implements EventHandler<MouseEvent> {
public CalculatorPane(){ public CalculatorPane(){
constructButtons();
setSpacing(15); setSpacing(15);
setPadding(new Insets(10)); setPadding(new Insets(10));
ioField = new TextField(); ioField = new TextField();
@ -29,14 +28,14 @@ public class CalculatorPane extends VBox implements EventHandler<MouseEvent> {
ioField.setEditable(false); ioField.setEditable(false);
ioField.setText(""); ioField.setText("");
ioField.setPrefHeight(15); ioField.setPrefHeight(15);
constructButtons();
} }
private void calculateAndDisplay() { private void calculateAndDisplay() {
if (subtracting) { if (subtracting) {
display(String.valueOf(firstOperand - Integer.parseInt(ioField.getText()))); display(String.valueOf(firstOperand - Integer.parseInt(ioField.getText())));
subtracting = false;
} }
else display(String.valueOf(firstOperand+Integer.parseInt(ioField.getText()))); else display(String.valueOf(firstOperand+Integer.parseInt(ioField.getText())));
} }
@ -61,6 +60,7 @@ public class CalculatorPane extends VBox implements EventHandler<MouseEvent> {
ioField.setText(result); ioField.setText(result);
} }
//Handle all number buttons
@Override @Override
public void handle(MouseEvent mouseEvent) { public void handle(MouseEvent mouseEvent) {
int pressedBtn = 0; int pressedBtn = 0;
@ -75,6 +75,7 @@ public class CalculatorPane extends VBox implements EventHandler<MouseEvent> {
ioField.setText(ioField.getText()+ pressedBtn); ioField.setText(ioField.getText()+ pressedBtn);
} }
else { else {
//TODO: removes prev digit. (cant place 2 or more digits for second operand.
ioField.setText(String.valueOf(pressedBtn)); ioField.setText(String.valueOf(pressedBtn));
} }
} }
@ -100,6 +101,7 @@ public class CalculatorPane extends VBox implements EventHandler<MouseEvent> {
btn.setOnMouseClicked(this); btn.setOnMouseClicked(this);
} }
//set Event handlers for op buttons
btnList[Buttons.CLEAR].setOnMouseClicked(e-> clear()); btnList[Buttons.CLEAR].setOnMouseClicked(e-> clear());
btnList[Buttons.PLUS].setOnMouseClicked(e -> add()); btnList[Buttons.PLUS].setOnMouseClicked(e -> add());
btnList[Buttons.MINUS].setOnMouseClicked(e -> subtract()); btnList[Buttons.MINUS].setOnMouseClicked(e -> subtract());