From 9ad79c0f2e53cdf076758d0d8f76d05eedf37181 Mon Sep 17 00:00:00 2001 From: Lukas Reichwein Date: Sun, 14 Jul 2019 20:35:18 +0200 Subject: [PATCH] connected matrixMultiplication to the multiply Button --- .../matrixcalc/MatrixCalcController.java | 31 ++++++++++++++----- .../com/ugsbo/gui/matrixCalcGui.fxml | 12 +++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java index 3b93482..bd7fbc1 100644 --- a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java @@ -3,6 +3,8 @@ package com.ugsbo.matrixcalc; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.text.Text; +import javafx.scene.text.TextAlignment; + import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -29,14 +31,29 @@ public class MatrixCalcController { */ @FXML public void initialize() { + /** + * Convert Strings to matricies, multiply them and output the result. + */ multiplyButton.setOnMouseClicked((event) -> { - String matrixA = matrixATextArea.getText(); - String matrixB = matrixBTextArea.getText(); - if (checkInput(matrixA)) { - // TODO matrixATextArea and matrixBTextArea need to be parsed to double[][] do - // this in an extern Methode maybe an extern class. - // MatrixCalcMath math = new MatrixCalcMath(); - // math.matrixMultiplication(matrixATextArea, matrixATextArea); + String stringMatrixA = matrixATextArea.getText(); + String stringMatrixB = matrixBTextArea.getText(); + if (checkInput(stringMatrixA) && checkInput(stringMatrixB)) { + MatrixCalcMath math = new MatrixCalcMath(); + double[][] matrixA = math.stringToMatrix(stringMatrixA); + double[][] matrixB = math.stringToMatrix(stringMatrixB); + double[][] result = math.matrixMultiplication(matrixA, matrixB); + + String resultString = ""; + for (int i = 0; i < result.length; i++) { + for (int j = 0; j < result[0].length; j++) { + resultString += result[i][j] + " "; + //System.out.println(result[i][j]); + } + resultString += "\n\n"; + } + //Display output + outputText.setText(resultString); + outputText.setTextAlignment(TextAlignment.CENTER); } // System.out.println(matrixATextArea.getText()); }); diff --git a/src/main/resources/com/ugsbo/gui/matrixCalcGui.fxml b/src/main/resources/com/ugsbo/gui/matrixCalcGui.fxml index abe1301..759bbba 100644 --- a/src/main/resources/com/ugsbo/gui/matrixCalcGui.fxml +++ b/src/main/resources/com/ugsbo/gui/matrixCalcGui.fxml @@ -1,11 +1,11 @@ - - - - + + + + - + @@ -27,6 +27,6 @@