Browse Source

connected matrixMultiplication to the multiply Button

featureMatrixCalculator
Lukas Reichwein 6 years ago
parent
commit
9ad79c0f2e
  1. 31
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java
  2. 12
      src/main/resources/com/ugsbo/gui/matrixCalcGui.fxml

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

12
src/main/resources/com/ugsbo/gui/matrixCalcGui.fxml

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Text?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ugsbo.matrixcalc.MatrixCalcController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ugsbo.matrixcalc.MatrixCalcController">
<children>
<AnchorPane prefHeight="200.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
@ -27,6 +27,6 @@
<TextArea fx:id="matrixBTextArea" layoutX="-15.0" layoutY="30.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
<Text fx:id="outputText" layoutX="14.0" layoutY="242.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="554.7294921875" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="210.0" />
<Text fx:id="outputText" layoutX="14.0" layoutY="242.0" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="JUSTIFY" wrappingWidth="554.7294921875" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="210.0" />
</children>
</AnchorPane>
Loading…
Cancel
Save