Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.9 KiB

  1. package com.ugsbo.matrixcalc;
  2. import javafx.fxml.FXML;
  3. import javafx.scene.control.*;
  4. import javafx.scene.text.Text;
  5. import javafx.scene.text.TextAlignment;
  6. public class MatrixCalcController {
  7. // Hier werden die fx:id Attribute verknuepft.
  8. @FXML
  9. private Button multiplyButton, addButton, DetAButton, DetBButton, substractButton, transposeButton;
  10. @FXML
  11. private Text errorText, outputText;
  12. @FXML
  13. private TextArea matrixATextArea, matrixBTextArea;
  14. /**
  15. * Konstructor is called before initialize()
  16. */
  17. public MatrixCalcController() {
  18. // Setup of some Fields could be defined here.
  19. }
  20. /**
  21. * Initializes the controller class. This method is automatically called after
  22. * the fxml file has been loaded.
  23. */
  24. @FXML
  25. public void initialize() {
  26. /**
  27. * Convert Strings to matricies, multiply them and output the result.
  28. */
  29. multiplyButton.setOnMouseClicked((event) -> {
  30. MatrixCalcMath math = new MatrixCalcMath();
  31. MatrixCalcIOUtils util = new MatrixCalcIOUtils();
  32. String stringMatrixA = matrixATextArea.getText();
  33. String stringMatrixB = matrixBTextArea.getText();
  34. try {
  35. } catch (Exception e) {
  36. //TODO: handle exception
  37. }
  38. double[][] matrixA = util.stringToMatrix(stringMatrixA);
  39. double[][] matrixB = util.stringToMatrix(stringMatrixB);
  40. double[][] result = math.matrixMultiplication(matrixA, matrixB);
  41. String DisplayableString = util.outputMatrixToOutputText(result);
  42. outputText.setText(DisplayableString);
  43. outputText.setTextAlignment(TextAlignment.CENTER);
  44. // System.out.println(matrixATextArea.getText());
  45. });
  46. transposeButton.setOnMouseClicked((event) -> {
  47. MatrixCalcMath math = new MatrixCalcMath();
  48. MatrixCalcIOUtils util = new MatrixCalcIOUtils();
  49. String stringMatrixA = matrixATextArea.getText();
  50. try {
  51. } catch (Exception e) {
  52. //TODO: handle exception
  53. }
  54. double[][] matrixA = util.stringToMatrix(stringMatrixA);
  55. double[][] result = math.matrixTransponation(matrixA);
  56. String DisplayableString = util.outputMatrixToOutputText(result);
  57. outputText.setText(DisplayableString);
  58. outputText.setTextAlignment(TextAlignment.CENTER);
  59. });
  60. addButton.setOnMouseClicked((event) -> {
  61. MatrixCalcMath math = new MatrixCalcMath();
  62. MatrixCalcIOUtils util = new MatrixCalcIOUtils();
  63. String stringMatrixA = matrixATextArea.getText();
  64. String stringMatrixB = matrixBTextArea.getText();
  65. try {
  66. } catch (Exception e) {
  67. //TODO: handle exception
  68. }
  69. double[][] matrixA = util.stringToMatrix(stringMatrixA);
  70. double[][] matrixB = util.stringToMatrix(stringMatrixB);
  71. double[][] result = math.matrixAddition(matrixA, matrixB);
  72. String DisplayableString = util.outputMatrixToOutputText(result);
  73. outputText.setText(DisplayableString);
  74. outputText.setTextAlignment(TextAlignment.CENTER);
  75. });
  76. substractButton.setOnMouseClicked((event) -> {
  77. MatrixCalcMath math = new MatrixCalcMath();
  78. MatrixCalcIOUtils util = new MatrixCalcIOUtils();
  79. String stringMatrixA = matrixATextArea.getText();
  80. String stringMatrixB = matrixBTextArea.getText();
  81. try {
  82. util.checkInput(stringMatrixA);
  83. } catch (Exception e) {
  84. outputText.setText(e.getMessage() + "A");
  85. outputText.setTextAlignment(TextAlignment.CENTER);
  86. }
  87. try {
  88. util.checkInput(stringMatrixB);
  89. } catch (Exception e) {
  90. outputText.setText(e.getMessage() + "B");
  91. outputText.setTextAlignment(TextAlignment.CENTER);
  92. }
  93. double[][] matrixA = util.stringToMatrix(stringMatrixA);
  94. double[][] matrixB = util.stringToMatrix(stringMatrixB);
  95. try {
  96. double[][] result = math.matrixSubstraction(matrixA, matrixB);
  97. String DisplayableString = util.outputMatrixToOutputText(result);
  98. outputText.setText(DisplayableString);
  99. outputText.setTextAlignment(TextAlignment.CENTER);
  100. } catch (Exception e) {
  101. outputText.setText(e.getMessage());
  102. outputText.setTextAlignment(TextAlignment.CENTER);
  103. }
  104. });
  105. DetAButton.setOnMouseClicked((event) -> {
  106. MatrixCalcMath math = new MatrixCalcMath();
  107. MatrixCalcIOUtils util = new MatrixCalcIOUtils();
  108. String stringMatrixA = matrixATextArea.getText();
  109. try {
  110. util.checkInput(stringMatrixA);
  111. } catch (IllegalArgumentException e) {
  112. outputText.setText(e.getMessage());
  113. outputText.setTextAlignment(TextAlignment.CENTER);
  114. }
  115. double[][] matrixA = util.stringToMatrix(stringMatrixA);
  116. try {
  117. double result = math.calcDeterminat(matrixA);
  118. String DisplayableString = Double.toString(result);
  119. outputText.setText(DisplayableString);
  120. outputText.setTextAlignment(TextAlignment.CENTER);
  121. } catch (IllegalArgumentException e) {
  122. outputText.setText(e.getMessage());
  123. outputText.setTextAlignment(TextAlignment.CENTER);
  124. }
  125. });
  126. DetBButton.setOnMouseClicked((event) -> {
  127. MatrixCalcMath math = new MatrixCalcMath();
  128. MatrixCalcIOUtils util = new MatrixCalcIOUtils();
  129. String stringMatrixB = matrixBTextArea.getText();
  130. try {
  131. util.checkInput(stringMatrixB);
  132. } catch (IllegalArgumentException e) {
  133. outputText.setText(e.getMessage());
  134. outputText.setTextAlignment(TextAlignment.CENTER);
  135. }
  136. double[][] matrixB = util.stringToMatrix(stringMatrixB);
  137. try {
  138. double result = math.calcDeterminat(matrixB);
  139. String DisplayableString = Double.toString(result);
  140. outputText.setText(DisplayableString);
  141. outputText.setTextAlignment(TextAlignment.CENTER);
  142. } catch (IllegalArgumentException e) {
  143. outputText.setText(e.getMessage());
  144. outputText.setTextAlignment(TextAlignment.CENTER);
  145. }
  146. });
  147. }
  148. }