From e54ce035e0c125be7399da407d76e6d43701c56e Mon Sep 17 00:00:00 2001 From: pbg2h21ama Date: Tue, 31 Jan 2023 14:57:37 +0100 Subject: [PATCH] Registrireung weiterentwickelt --- .../example/vpr_javafx/HelloController.java | 31 +++++++++- .../example/vpr_javafx/Registration-view.fxml | 59 +++++++++---------- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/example/vpr_javafx/HelloController.java b/src/main/java/com/example/vpr_javafx/HelloController.java index d8130fe..6e530dd 100644 --- a/src/main/java/com/example/vpr_javafx/HelloController.java +++ b/src/main/java/com/example/vpr_javafx/HelloController.java @@ -13,6 +13,7 @@ import javafx.stage.Stage; import java.io.Console; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -20,6 +21,7 @@ import java.util.HashMap; import java.util.List; public class HelloController { + @FXML private Label lMonH1; @FXML @@ -84,6 +86,11 @@ public class HelloController { @FXML private TextField tfPhone; + @FXML + public TextField tfName; + @FXML + public TextField tfChild; + @FXML private PasswordField pfPassword; @FXML @@ -235,7 +242,7 @@ public class HelloController { + "k: Nüsse; l: Sellerie;\n" + "m: Fische; n: Lupinen\n\n" + "1: Nitrit-Pökelsalz\n" - + "2:Phosphat\n" + + "2: Phosphat\n" + "3: Nitrat\n" + "4: Antioxidationsmittel\n" + "5: Farbstoff\n" @@ -244,4 +251,26 @@ public class HelloController { + "8: Konservierungsstoff"); } + @FXML + protected void OnRegistrationButton(ActionEvent event) throws IOException + { + Alert alert = new Alert(Alert.AlertType.WARNING); + Data validData = new Data("user.txt"); + + if (tfName.getText().isEmpty() || tfPhone.getText().isEmpty() || tfChild.getText().isEmpty()) + { + alert.setContentText("Registrierungsdaten unvollständig"); + } + else if (validData.validateData(tfPhone, pfPassword)) + { + try (FileWriter writer = new FileWriter("user.txt")){ + writer.write(tfName.getText() + ";" + tfPhone.getText() + ";" + tfChild.getText() + ";" + pfPassword.getText()); + writer.flush(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } } \ No newline at end of file diff --git a/src/main/resources/com/example/vpr_javafx/Registration-view.fxml b/src/main/resources/com/example/vpr_javafx/Registration-view.fxml index 481d6c9..7a41d50 100644 --- a/src/main/resources/com/example/vpr_javafx/Registration-view.fxml +++ b/src/main/resources/com/example/vpr_javafx/Registration-view.fxml @@ -4,34 +4,31 @@ - - - - - - - - - - - - - - - - -