From 0488d50f7942d720f6ca0a137aaa93f90e81957d Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Thu, 17 Mar 2022 21:25:07 +0100 Subject: [PATCH] =?UTF-8?q?Aufgabe=201=20ausgef=C3=BChrt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch/zhaw/prog2/application/MainWindow.java | 4 ++-- .../application/MainWindowController.java | 23 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindow.java b/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindow.java index 0a6f0af..4a8b933 100644 --- a/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindow.java +++ b/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindow.java @@ -8,7 +8,7 @@ import javafx.stage.Stage; public class MainWindow extends Application { - + WordModel wordModel = new WordModel(); @Override public void start(Stage primaryStage) throws Exception { @@ -23,7 +23,7 @@ public class MainWindow extends Application { MainWindowController mainWindowController = loader.getController(); //mainWindowController.connectProperties(); //nicht benötigt, da in der Methode MainWindowController in initialize aufgerufen wird. - + mainWindowController.setWordModel(wordModel); Scene scene = new Scene(rootNode); diff --git a/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindowController.java b/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindowController.java index 3de2324..de98d5a 100644 --- a/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindowController.java +++ b/code/FXML-WordCloud/src/main/java/ch/zhaw/prog2/application/MainWindowController.java @@ -6,9 +6,12 @@ import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; +import java.util.Locale; + public class MainWindowController { + WordModelDecorator wordModelDecorator; public void initialize(){ connectProperties(); @@ -25,18 +28,26 @@ public class MainWindowController { @FXML void hinzufuegenText(ActionEvent event) { - String text = textHistory.getText(); - text += textEingabe.getText() + "\n"; - textHistory.setText(text); - textEingabe.clear(); - } + String[] text = textEingabe.getText().toLowerCase().split(" "); + for(String word : text) { + wordModelDecorator.addWord(word); + } + } @FXML void leerenTextEingabe(ActionEvent event) { textEingabe.clear(); } - + void setWordModel(WordModel wordModel){ + wordModelDecorator = new WordModelDecorator(wordModel); + wordModelDecorator.addListener(new IsObserver() { + @Override + public void update() { + textHistory.setText(wordModel.toString()); + } + }); + } void connectProperties() { // erste Möglichkeit