From af901a38fc516cf1efc692cef356ac2840e461f9 Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Thu, 17 Mar 2022 16:35:18 +0100 Subject: [PATCH] =?UTF-8?q?Workshop=20durchgef=C3=BChrt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 +++ app/build.gradle | 5 +++ .../java/ch/zhaw/prog2/application/App.java | 8 ++-- .../ch/zhaw/prog2/application/MainWindow.java | 39 ++++++++++++++++ .../application/MainWindowController.java | 44 +++++++++++++++++++ .../ch/zhaw/prog2/application/MainWindow.fxml | 31 +++++++++++++ 6 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/ch/zhaw/prog2/application/MainWindow.java create mode 100644 app/src/main/java/ch/zhaw/prog2/application/MainWindowController.java create mode 100644 app/src/main/resources/ch/zhaw/prog2/application/MainWindow.fxml diff --git a/.gitignore b/.gitignore index a1c2a23..47af25b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,9 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/app/build.gradle b/app/build.gradle index a648943..e4ba5ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,6 +9,11 @@ plugins { // Apply the application plugin to add support for building a CLI application in Java. id 'application' + id 'org.openjfx.javafxplugin' version '0.0.12' +} +javafx { + version = '17' + modules = [ 'javafx.controls', 'javafx.fxml' ] } repositories { diff --git a/app/src/main/java/ch/zhaw/prog2/application/App.java b/app/src/main/java/ch/zhaw/prog2/application/App.java index db551f5..b4da2c0 100644 --- a/app/src/main/java/ch/zhaw/prog2/application/App.java +++ b/app/src/main/java/ch/zhaw/prog2/application/App.java @@ -3,12 +3,10 @@ */ package ch.zhaw.prog2.application; -public class App { - public String getGreeting() { - return "Hello World!"; - } +import javafx.application.Application; +public class App { public static void main(String[] args) { - System.out.println(new App().getGreeting()); + Application.launch(MainWindow.class, args); } } diff --git a/app/src/main/java/ch/zhaw/prog2/application/MainWindow.java b/app/src/main/java/ch/zhaw/prog2/application/MainWindow.java new file mode 100644 index 0000000..5f6cc9a --- /dev/null +++ b/app/src/main/java/ch/zhaw/prog2/application/MainWindow.java @@ -0,0 +1,39 @@ +package ch.zhaw.prog2.application; + +import javafx.application.Application; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.Pane; +import javafx.stage.Stage; + +public class MainWindow extends Application { + + + + @Override + public void start(Stage primaryStage) throws Exception { + openMainWindow(primaryStage); + } + + private void openMainWindow(Stage stage) { + try { + FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml")); + + Pane rootNode = loader.load(); + + MainWindowController mainWindowController = loader.getController(); + //mainWindowController.connectProperties(); //nicht benötigt, da in der Methode MainWindowController in initialize aufgerufen wird. + + + Scene scene = new Scene(rootNode); + + stage.setScene(scene); + stage.show(); + } catch(Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/app/src/main/java/ch/zhaw/prog2/application/MainWindowController.java b/app/src/main/java/ch/zhaw/prog2/application/MainWindowController.java new file mode 100644 index 0000000..20522e2 --- /dev/null +++ b/app/src/main/java/ch/zhaw/prog2/application/MainWindowController.java @@ -0,0 +1,44 @@ +package ch.zhaw.prog2.application; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; + +public class MainWindowController { + + public void initialize(){ + connectProperties(); + } + + @FXML + private Label labelTitel; + + @FXML + private TextField textEingabe; + + @FXML + private TextArea textHistory; + + @FXML + void hinzufuegenText(ActionEvent event) { + String text = textHistory.getText(); + text += textEingabe.getText() + "\n"; + textHistory.setText(text); + textEingabe.clear(); + } + + @FXML + void leerenTextEingabe(ActionEvent event) { + textEingabe.clear(); + } + + + + void connectProperties() { + // erste Möglichkeit + labelTitel.textProperty().bind(textEingabe.textProperty()); + } + +} diff --git a/app/src/main/resources/ch/zhaw/prog2/application/MainWindow.fxml b/app/src/main/resources/ch/zhaw/prog2/application/MainWindow.fxml new file mode 100644 index 0000000..458bd9b --- /dev/null +++ b/app/src/main/resources/ch/zhaw/prog2/application/MainWindow.fxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + +