From c54543a43f323b37f375d6f564a178f8c7c4d4b2 Mon Sep 17 00:00:00 2001 From: Jan <janschubert93@web.de> Date: Tue, 3 Dec 2019 11:35:24 +0100 Subject: [PATCH] App --- src/main/java/projekt/enigma/App.java | 57 +++++++++++++-------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/main/java/projekt/enigma/App.java b/src/main/java/projekt/enigma/App.java index 64ffd20..9765e0a 100644 --- a/src/main/java/projekt/enigma/App.java +++ b/src/main/java/projekt/enigma/App.java @@ -2,6 +2,7 @@ package projekt.enigma; import javafx.application.Application; import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; @@ -18,61 +19,59 @@ import java.io.IOException; */ public class App extends Application { - Scene sce1, sce2; + private Scene sce1, sce2; @Override public void start(Stage primaryStage) throws IOException { Codierer cod = new Codierer(); - primaryStage.setTitle("Kenngruppenabfrage"); -//Scene 1 - Label label1= new Label("Bitte Kenngruppe eingeben!"); - label1.setTranslateX(55); - Label l1=new Label(""); - Label l2 = new Label(""); - TextField tfield=new TextField(); - Button button1= new Button("Kenngruppe setzen!"); + Label label1 = new Label("Bitte Kenngruppe eingeben!"); + TextField tfKenngruppe = new TextField(); + Button button1 = new Button("Kenngruppe setzen!"); + button1.setTranslateX(10); VBox layout1 = new VBox(); - // kc.btnGui(primaryStage, sce2); + layout1.setSpacing(30); + layout1.setPadding(new Insets(15,15,15,15)); button1.setOnAction(e -> { - if (tfield.getText().length() < 9) { - for (char c : tfield.getText().toCharArray()) { - if (c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f' || c == 'g' || c == 'h' || c == 'i' || c == 'j' || c == 'k' || c == 'l' || c == 'm' || c == 'n' || c == 'o' || c == 'p' || c == 'q' || c == 'r' || c == 's' || c == 't' || c == 'u' || c == 'v' || c == 'w' || c == 'x' || c == 'y' || c == 'z' || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' || c == 'G' || c == 'H' || c == 'I' || c == 'J' || c == 'K' || c == 'L' || c == 'M' || c == 'N' || c == 'O' || c == 'P' || c == 'Q' || c == 'R' || c == 'S' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X' || c == 'Y' || c == 'Z') { - cod.setKenngruppe(tfield.getText()); - primaryStage.setScene(sce2); - } + String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + boolean error = false; + for (char c : tfKenngruppe.getText().toUpperCase().toCharArray()) { + if (!alphabet.contains(String.valueOf(c))) { + error = true; + break; } - }else{ - tfield.setStyle("-fx-background-color:#FF0000"); - tfield.setText("Fehlerhafte Kenngruppe!"); + } + if (tfKenngruppe.getText().length() < 9 && !error) { + cod.setKenngruppe(tfKenngruppe.getText().toUpperCase()); + primaryStage.setScene(sce2); + } else { + tfKenngruppe.setStyle("-fx-background-color:#FF0000"); + tfKenngruppe.setText("Fehlerhafte Kenngruppe!"); } }); - layout1.getChildren().addAll(label1,l1,tfield,l2,button1); - - //sce1= new Scene(loadFXML("kenngruppe"), 300, 250); + layout1.getChildren().addAll(label1, tfKenngruppe, button1); - sce1=new Scene(layout1,234,137); + sce1 = new Scene(layout1); sce2 = new Scene(loadFXML("gui"), 962, 677); + primaryStage.setScene(sce1); primaryStage.show(); } - private static Parent loadFXML(String fxml) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); - return fxmlLoader.load(); - } - + private static Parent loadFXML(String fxml) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); + return fxmlLoader.load(); + } public static void main(String[] args) { launch(args); } - // /** // * TODO Dokumentieren // */ -- GitLab