Browse Source

Added try catch around the operations of addition, transponation and multiplication.

featureMatrixCalculator
Lukas Reichwein 5 years ago
parent
commit
a1ec4a577c
  1. 24
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java

24
src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java

@ -43,13 +43,19 @@ public class MatrixCalcController {
double[][] matrixA = util.stringToMatrix(stringMatrixA); double[][] matrixA = util.stringToMatrix(stringMatrixA);
double[][] matrixB = util.stringToMatrix(stringMatrixB); double[][] matrixB = util.stringToMatrix(stringMatrixB);
try {
double[][] result = math.matrixMultiplication(matrixA, matrixB); double[][] result = math.matrixMultiplication(matrixA, matrixB);
String DisplayableString = util.outputMatrixToOutputText(result); String DisplayableString = util.outputMatrixToOutputText(result);
outputText.setText(DisplayableString); outputText.setText(DisplayableString);
outputText.setTextAlignment(TextAlignment.CENTER); outputText.setTextAlignment(TextAlignment.CENTER);
// System.out.println(matrixATextArea.getText());
} catch (IllegalArgumentException e) {
outputText.setText(e.getMessage());
outputText.setTextAlignment(TextAlignment.CENTER);
}
}); });
transposeButton.setOnMouseClicked((event) -> { transposeButton.setOnMouseClicked((event) -> {
@ -59,12 +65,19 @@ public class MatrixCalcController {
checkInputAndDisplayIfInputIsNotValid(stringMatrix, 1); checkInputAndDisplayIfInputIsNotValid(stringMatrix, 1);
double[][] matrixA = util.stringToMatrix(stringMatrixA); double[][] matrixA = util.stringToMatrix(stringMatrixA);
try {
double[][] result = math.matrixTransponation(matrixA); double[][] result = math.matrixTransponation(matrixA);
String DisplayableString = util.outputMatrixToOutputText(result); String DisplayableString = util.outputMatrixToOutputText(result);
outputText.setText(DisplayableString); outputText.setText(DisplayableString);
outputText.setTextAlignment(TextAlignment.CENTER); outputText.setTextAlignment(TextAlignment.CENTER);
} catch (IllegalArgumentException e) {
outputText.setText(e.getMessage());
outputText.setTextAlignment(TextAlignment.CENTER);
}
}); });
addButton.setOnMouseClicked((event) -> { addButton.setOnMouseClicked((event) -> {
@ -76,12 +89,19 @@ public class MatrixCalcController {
double[][] matrixA = util.stringToMatrix(stringMatrixA); double[][] matrixA = util.stringToMatrix(stringMatrixA);
double[][] matrixB = util.stringToMatrix(stringMatrixB); double[][] matrixB = util.stringToMatrix(stringMatrixB);
try {
double[][] result = math.matrixAddition(matrixA, matrixB); double[][] result = math.matrixAddition(matrixA, matrixB);
String DisplayableString = util.outputMatrixToOutputText(result); String DisplayableString = util.outputMatrixToOutputText(result);
outputText.setText(DisplayableString); outputText.setText(DisplayableString);
outputText.setTextAlignment(TextAlignment.CENTER); outputText.setTextAlignment(TextAlignment.CENTER);
} catch (IllegalArgumentException e) {
outputText.setText(e.getMessage());
outputText.setTextAlignment(TextAlignment.CENTER);
}
}); });
substractButton.setOnMouseClicked((event) -> { substractButton.setOnMouseClicked((event) -> {
@ -101,7 +121,7 @@ public class MatrixCalcController {
outputText.setText(DisplayableString); outputText.setText(DisplayableString);
outputText.setTextAlignment(TextAlignment.CENTER); outputText.setTextAlignment(TextAlignment.CENTER);
} catch (Exception e) {
} catch (IllegalArgumentException e) {
outputText.setText(e.getMessage()); outputText.setText(e.getMessage());
outputText.setTextAlignment(TextAlignment.CENTER); outputText.setTextAlignment(TextAlignment.CENTER);

Loading…
Cancel
Save