From bbf41a8091a8b29fa358d78bab1057c76b527095 Mon Sep 17 00:00:00 2001 From: Jan <janschubert93@web.de> Date: Wed, 27 Nov 2019 10:42:46 +0100 Subject: [PATCH] Walzen, Ringe und Startwerte einstellen --- src/main/java/Enigma/GuiController.java | 346 ++++++++++++++---------- src/main/resources/Enigma/gui.fxml | 113 +++----- 2 files changed, 235 insertions(+), 224 deletions(-) diff --git a/src/main/java/Enigma/GuiController.java b/src/main/java/Enigma/GuiController.java index 7e444ce..15a5fee 100644 --- a/src/main/java/Enigma/GuiController.java +++ b/src/main/java/Enigma/GuiController.java @@ -1,11 +1,17 @@ package Enigma; import javafx.fxml.FXML; +import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.MenuButton; import javafx.scene.control.MenuItem; +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.beans.EventHandler; import java.util.ArrayList; import java.util.List; @@ -13,213 +19,255 @@ public class GuiController { @FXML private MenuButton w1; -// -// @FXML -// private MenuItem w1I; -// -// @FXML -// private MenuItem w1II; -// -// @FXML -// private MenuItem w1III; -// @FXML -// private MenuItem w1IV; -// -// @FXML -// private MenuItem w1V; @FXML private MenuButton w2; + @FXML - private MenuItem w2I; + private MenuButton w3; @FXML - private MenuItem w2II; + private MenuButton r1; @FXML - private MenuItem w2III; + private MenuButton r2; @FXML - private MenuItem w2IV; + private MenuButton r3; + @FXML - private MenuItem w2V; + private MenuButton a1; @FXML - private MenuButton w3; + private MenuButton a3; @FXML - private MenuItem w3I; + private MenuButton a2; + @FXML + private Button L; @FXML - private MenuItem w3II; + private Button P; @FXML - private MenuItem w3III; + private Button Y; + @FXML - private MenuItem w3IV; + private Button X; @FXML - private MenuItem w3V; + private Button C; + @FXML + private Button V; @FXML - void w3I(ActionEvent event) { - } + private Button B; @FXML - void w3II(ActionEvent event) { - } + private Button N; @FXML - void w3III(ActionEvent event) { - } + private Button M; + @FXML - void w3IV(ActionEvent event) { - } + private Button A; + @FXML - void w3V(ActionEvent event) { - } + private Button S; @FXML - void btnsenden(ActionEvent event) { - } - public void btnsenden(){ + private Button D; - } -// @FXML -// void w1I(ActionEvent event) { -// } -// @FXML -// void w1II(ActionEvent event) { -// } -// @FXML -// void w1III(ActionEvent event) { -// } -// @FXML -// void w1IV(ActionEvent event) { -// } -// @FXML -// void w1V(ActionEvent event) { -// } + @FXML + private Button F; @FXML - void w2I(ActionEvent event) { - } + private Button G; + @FXML - void w2II(ActionEvent event) { - } + private Button H; + @FXML - void w2III(ActionEvent event) { - } + private Button J; + @FXML - void w2IV(ActionEvent event) { - } + private Button K; + @FXML - void w2V(ActionEvent event) { - } + private Button Q; -// // Action Listener für erste Walze -// public void w1I(){ -// w1.setText(w1I.getText()); -// } -// public void w1II(){ -// w1.setText(w1II.getText()); -// } -// public void w1III(){ -// w1.setText(w1III.getText()); -// } -// public void w1IV(){ -// w1.setText(w1IV.getText()); -// } -// public void w1V(){ -// w1.setText(w1V.getText()); -// } - // Action Listener für zweite Walze - public void w2I(){ - w2.setText(w2I.getText()); - } - public void w2II(){ - w2.setText(w2II.getText()); - } - public void w2III(){ - w2.setText(w2III.getText()); - } - public void w2IV(){ - w2.setText(w2IV.getText()); - } - public void w2V(){ - w2.setText(w2V.getText()); - } - // Action Listener für dritte Walze - public void w3I(){ - w3.setText(w3I.getText()); - } - public void w3II(){ - w3.setText(w3II.getText()); - } - public void w3III(){ - w3.setText(w3III.getText()); + @FXML + private Button W; + + @FXML + private Button E; + + @FXML + private Button R; + + @FXML + private Button T; + + @FXML + private Button Z; + + @FXML + private Button U; + + @FXML + private Button I; + + @FXML + private Button O; + + + @FXML + void gedrueckteTaste(ActionEvent event) { } - public void w3IV(){ - w3.setText(w3IV.getText()); + public void gedrueckteTaste(){ } - public void w3V(){ - w3.setText(w3V.getText()); + +// public void gedrueckteTaste() { +// txt.setText("hello"); + + // } +// public void action(ActionEvent ae){ +// if (ae.getSource()==) +// } + + @FXML + void empfangen(ActionEvent event) { + } + public void empfangen(){ - public void listener(MenuButton mb, MenuItem mi){ - mb.setText(mi.getText()); } + + +// txtoriginal.setText(bn.getText()); +// } + + // public void gedrueckteTaste(Button bn){ + + + + + // } + + + + +// public void gedrueckteTaste (){ +// +// new EventHandler<KeyEvent>(){ // -// public void walzenListener(){ -// MenuItem[] buttons = {w1I,w1II,w1II,w1IV,w1V}; -// for (int i =0; i<6; i++) { -// listener(w1, buttons[i]); // } +// +// +// // } + @FXML - void initialize() { + void btnsenden(ActionEvent event) { + } + public void btnsenden(){ -// for (int i =0; i<6; i++) { -// -// mi.add(new MenuItem("W"+i)); -// } + } - ArrayList<MenuItem> mi; - for (int i =0; i<6; i++) { - String[] str={"I","II","III","IV","V"}; - MenuItem mb2 = new MenuItem("W"+i); - w1.getItems().add(mb2); - // listener(w1,mb2); + + + /** + * Methode zum setzen des menuButton Textes auf das ausgewählte MenuItem + * @param mb : MenuButton der Walze + * @param mi : MenuItem + */ + private void listener(MenuButton mb, MenuItem mi){ + mb.setText(mi.getText()); + } + + /** + * Methode zur Erstellung der Einträge und Action Listener für die einzelnen Menüs + * @param button : Button für die die Einträge erstellt werden sollen + */ + private void menu(MenuButton button, String[] str) { + ArrayList<MenuItem> mi = new ArrayList<>(); + for (int i = 0; i < str.length; i++) { + + //Eintrag aus str der Arraylist mi hinzufügen + mi.add(new MenuItem(str[i])); + //MenuItem mi dem Button button hinzufügen + button.getItems().add(mi.get(i)); + int finalI = i; + //Listener für die einzelnen Einträge + ArrayList<MenuItem> finalMi = mi; + mi.get(i).setOnAction(e -> { + listener(button, finalMi.get(finalI)); + }); } - // listener(w1,); - - - // walzenListener(); - - assert w1 != null : "fx:id=\"w1\" was not injected: check your FXML file 'primary.fxml'."; -// assert w1I != null : "fx:id=\"w1I\" was not injected: check your FXML file 'primary.fxml'."; -// assert w1II != null : "fx:id=\"w1II\" was not injected: check your FXML file 'primary.fxml'."; -// assert w1III != null : "fx:id=\"w1III\" was not injected: check your FXML file 'primary.fxml'."; -// assert w1IV != null : "fx:id=\"w1IV\" was not injected: check your FXML file 'primary.fxml'."; -// assert w1V != null : "fx:id=\"w1V\" was not injected: check your FXML file 'primary.fxml'."; - assert w3 != null : "fx:id=\"w3\" was not injected: check your FXML file 'primary.fxml'."; - assert w3I != null : "fx:id=\"w3I\" was not injected: check your FXML file 'primary.fxml'."; - assert w3II != null : "fx:id=\"w3II\" was not injected: check your FXML file 'primary.fxml'."; - assert w3III != null : "fx:id=\"w3III\" was not injected: check your FXML file 'primary.fxml'."; - assert w3IV != null : "fx:id=\"w3IV\" was not injected: check your FXML file 'primary.fxml'."; - assert w3V != null : "fx:id=\"w3V\" was not injected: check your FXML file 'primary.fxml'."; - assert w2 != null : "fx:id=\"w2\" was not injected: check your FXML file 'primary.fxml'."; - assert w2I != null : "fx:id=\"w2I\" was not injected: check your FXML file 'primary.fxml'."; - assert w2II != null : "fx:id=\"w2II\" was not injected: check your FXML file 'primary.fxml'."; - assert w2III != null : "fx:id=\"w2III\" was not injected: check your FXML file 'primary.fxml'."; - assert w2IV != null : "fx:id=\"w2IV\" was not injected: check your FXML file 'primary.fxml'."; - assert w2V != null : "fx:id=\"w2V\" was not injected: check your FXML file 'primary.fxml'."; + } + @FXML + private Button löschen; + @FXML + void initialize() { + String[] str={"I", "II", "III", "IV", "V"}; + String[] num ={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26"}; + String[] bs ={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; + + //Einträge für Walzen + menu(w1, str); + menu(w2, str); + menu(w3, str); + //Einträge für die Ringe + menu(r1, num); + menu(r2, num); + menu(r3, num); + //Einträge für die Startpositionen + menu(a1, bs); + menu(a2, bs); + menu(a3, bs); + + assert L != null : "fx:id=\"L\" was not injected: check your FXML file 'gui.fxml'."; + assert P != null : "fx:id=\"P\" was not injected: check your FXML file 'gui.fxml'."; + assert Y != null : "fx:id=\"Y\" was not injected: check your FXML file 'gui.fxml'."; + assert X != null : "fx:id=\"X\" was not injected: check your FXML file 'gui.fxml'."; + assert C != null : "fx:id=\"C\" was not injected: check your FXML file 'gui.fxml'."; + assert V != null : "fx:id=\"V\" was not injected: check your FXML file 'gui.fxml'."; + assert B != null : "fx:id=\"B\" was not injected: check your FXML file 'gui.fxml'."; + assert N != null : "fx:id=\"N\" was not injected: check your FXML file 'gui.fxml'."; + assert M != null : "fx:id=\"M\" was not injected: check your FXML file 'gui.fxml'."; + assert A != null : "fx:id=\"A\" was not injected: check your FXML file 'gui.fxml'."; + assert S != null : "fx:id=\"S\" was not injected: check your FXML file 'gui.fxml'."; + assert D != null : "fx:id=\"D\" was not injected: check your FXML file 'gui.fxml'."; + assert F != null : "fx:id=\"F\" was not injected: check your FXML file 'gui.fxml'."; + assert G != null : "fx:id=\"G\" was not injected: check your FXML file 'gui.fxml'."; + assert H != null : "fx:id=\"H\" was not injected: check your FXML file 'gui.fxml'."; + assert J != null : "fx:id=\"J\" was not injected: check your FXML file 'gui.fxml'."; + assert K != null : "fx:id=\"K\" was not injected: check your FXML file 'gui.fxml'."; + assert Q != null : "fx:id=\"Q\" was not injected: check your FXML file 'gui.fxml'."; + assert W != null : "fx:id=\"W\" was not injected: check your FXML file 'gui.fxml'."; + assert E != null : "fx:id=\"E\" was not injected: check your FXML file 'gui.fxml'."; + assert R != null : "fx:id=\"R\" was not injected: check your FXML file 'gui.fxml'."; + assert T != null : "fx:id=\"T\" was not injected: check your FXML file 'gui.fxml'."; + assert Z != null : "fx:id=\"Z\" was not injected: check your FXML file 'gui.fxml'."; + assert U != null : "fx:id=\"U\" was not injected: check your FXML file 'gui.fxml'."; + assert I != null : "fx:id=\"I\" was not injected: check your FXML file 'gui.fxml'."; + assert O != null : "fx:id=\"O\" was not injected: check your FXML file 'gui.fxml'."; + assert löschen != null : "fx:id=\"löschen\" was not injected: check your FXML file 'gui.fxml'."; + assert w1 != null : "fx:id=\"w1\" was not injected: check your FXML file 'gui.fxml'."; + assert w3 != null : "fx:id=\"w3\" was not injected: check your FXML file 'gui.fxml'."; + assert w2 != null : "fx:id=\"w2\" was not injected: check your FXML file 'gui.fxml'."; + assert r3 != null : "fx:id=\"r3\" was not injected: check your FXML file 'gui.fxml'."; + assert r2 != null : "fx:id=\"r2\" was not injected: check your FXML file 'gui.fxml'."; + assert a1 != null : "fx:id=\"a1\" was not injected: check your FXML file 'gui.fxml'."; + assert a3 != null : "fx:id=\"a3\" was not injected: check your FXML file 'gui.fxml'."; + assert a2 != null : "fx:id=\"a2\" was not injected: check your FXML file 'gui.fxml'."; + assert r1 != null : "fx:id=\"r1\" was not injected: check your FXML file 'gui.fxml'."; } } diff --git a/src/main/resources/Enigma/gui.fxml b/src/main/resources/Enigma/gui.fxml index ae2b648..e020f97 100644 --- a/src/main/resources/Enigma/gui.fxml +++ b/src/main/resources/Enigma/gui.fxml @@ -22,41 +22,41 @@ <TextField layoutX="693.0" layoutY="625.0" prefHeight="25.0" prefWidth="48.0" /> <ButtonBar layoutX="31.0" layoutY="570.0" prefHeight="36.0" prefWidth="860.0"> <buttons> - <Button mnemonicParsing="false" text="L" /> - <Button mnemonicParsing="false" text="P" /> - <Button mnemonicParsing="false" text="Y" /> - <Button mnemonicParsing="false" text="X" /> - <Button mnemonicParsing="false" text="C" /> - <Button mnemonicParsing="false" text="V" /> - <Button mnemonicParsing="false" text="B" /> - <Button mnemonicParsing="false" text="N" /> - <Button mnemonicParsing="false" text="M" /> + <Button fx:id="L" mnemonicParsing="false" onAction="#gedrueckteTaste" text="L" /> + <Button fx:id="P" mnemonicParsing="false" onAction="#gedrueckteTaste" text="P" /> + <Button fx:id="Y" mnemonicParsing="false" onAction="#gedrueckteTaste" text="Y" /> + <Button fx:id="X" mnemonicParsing="false" onAction="#gedrueckteTaste" text="X" /> + <Button fx:id="C" mnemonicParsing="false" onAction="#gedrueckteTaste" text="C" /> + <Button fx:id="V" mnemonicParsing="false" onAction="#gedrueckteTaste" text="V" /> + <Button fx:id="B" mnemonicParsing="false" onAction="#gedrueckteTaste" text="B" /> + <Button fx:id="N" mnemonicParsing="false" onAction="#gedrueckteTaste" text="N" /> + <Button fx:id="M" mnemonicParsing="false" onAction="#gedrueckteTaste" text="M" /> </buttons> </ButtonBar> <ButtonBar layoutX="15.0" layoutY="534.0" prefHeight="36.0" prefWidth="860.0"> <buttons> - <Button mnemonicParsing="false" text="A" /> - <Button mnemonicParsing="false" text="S" /> - <Button mnemonicParsing="false" text="D" /> - <Button mnemonicParsing="false" text="F" /> - <Button mnemonicParsing="false" text="G" /> - <Button mnemonicParsing="false" text="H" /> - <Button mnemonicParsing="false" text="J" /> - <Button mnemonicParsing="false" text="K" /> + <Button fx:id="A" mnemonicParsing="false" onAction="#gedrueckteTaste" text="A" /> + <Button fx:id="S" mnemonicParsing="false" onAction="#gedrueckteTaste" text="S" /> + <Button fx:id="D" mnemonicParsing="false" onAction="#gedrueckteTaste" text="D" /> + <Button fx:id="F" mnemonicParsing="false" onAction="#gedrueckteTaste" text="F" /> + <Button fx:id="G" mnemonicParsing="false" onAction="#gedrueckteTaste" text="G" /> + <Button fx:id="H" mnemonicParsing="false" onAction="#gedrueckteTaste" text="H" /> + <Button fx:id="J" mnemonicParsing="false" onAction="#gedrueckteTaste" text="J" /> + <Button fx:id="K" mnemonicParsing="false" onAction="#gedrueckteTaste" text="K" /> </buttons> </ButtonBar> <ButtonBar layoutX="22.0" layoutY="491.0" prefHeight="25.0" prefWidth="583.0"> <buttons> - <Button minWidth="13.0" mnemonicParsing="false" prefHeight="25.0" text="Q" /> - <Button mnemonicParsing="false" text="W" /> - <Button mnemonicParsing="false" text="E" /> - <Button mnemonicParsing="false" text="R" /> - <Button mnemonicParsing="false" text="T" /> - <Button mnemonicParsing="false" text="Z" /> - <Button mnemonicParsing="false" text="U" /> - <Button mnemonicParsing="false" text="I" /> - <Button mnemonicParsing="false" text="O" /> - <Button mnemonicParsing="false" text="Löschen" /> + <Button fx:id="Q" minWidth="13.0" mnemonicParsing="false" onAction="#gedrueckteTaste" prefHeight="25.0" text="Q" /> + <Button fx:id="W" mnemonicParsing="false" onAction="#gedrueckteTaste" text="W" /> + <Button fx:id="E" mnemonicParsing="false" onAction="#gedrueckteTaste" text="E" /> + <Button fx:id="R" mnemonicParsing="false" onAction="#gedrueckteTaste" text="R" /> + <Button fx:id="T" mnemonicParsing="false" onAction="#gedrueckteTaste" text="T" /> + <Button fx:id="Z" mnemonicParsing="false" onAction="#gedrueckteTaste" text="Z" /> + <Button fx:id="U" mnemonicParsing="false" onAction="#gedrueckteTaste" text="U" /> + <Button fx:id="I" mnemonicParsing="false" onAction="#gedrueckteTaste" text="I" /> + <Button fx:id="O" mnemonicParsing="false" onAction="#gedrueckteTaste" text="O" /> + <Button fx:id="löschen" mnemonicParsing="false" text="Löschen" /> </buttons> </ButtonBar> <ButtonBar layoutX="39.0" layoutY="418.0" prefHeight="36.0" prefWidth="860.0"> @@ -98,31 +98,10 @@ </buttons> </ButtonBar> <MenuButton fx:id="w1" layoutX="91.0" layoutY="76.0" mnemonicParsing="false" text="I"> -<!-- <items>--> -<!-- <MenuItem fx:id="w1I" mnemonicParsing="false" onAction="#w1I" text="I" />--> -<!-- <MenuItem fx:id="w1II" mnemonicParsing="false" onAction="#w1II" text="II" />--> -<!-- <MenuItem fx:id="w1III" mnemonicParsing="false" onAction="#w1III" text="III" />--> -<!-- <MenuItem fx:id="w1IV" mnemonicParsing="false" onAction="#w1IV" text="IV" />--> -<!-- <MenuItem fx:id="w1V" mnemonicParsing="false" onAction="#w1V" text="V" />--> -<!-- </items>--> </MenuButton> <MenuButton fx:id="w3" layoutX="171.0" layoutY="76.0" mnemonicParsing="false" text="I"> - <items> - <MenuItem fx:id="w3I" mnemonicParsing="false" onAction="#w3I" text="I" /> - <MenuItem fx:id="w3II" mnemonicParsing="false" onAction="#w3II" text="II" /> - <MenuItem fx:id="w3III" mnemonicParsing="false" onAction="#w3III" text="III" /> - <MenuItem fx:id="w3IV" mnemonicParsing="false" onAction="#w3IV" text="IV" /> - <MenuItem fx:id="w3V" mnemonicParsing="false" onAction="#w3V" text="V" /> - </items> </MenuButton> <MenuButton fx:id="w2" layoutX="133.0" layoutY="76.0" mnemonicParsing="false" text="I"> - <items> - <MenuItem fx:id="w2I" mnemonicParsing="false" onAction="#w2I" text="I" /> - <MenuItem fx:id="w2II" mnemonicParsing="false" onAction="#w2II" text="II" /> - <MenuItem fx:id="w2III" mnemonicParsing="false" onAction="#w2III" text="III" /> - <MenuItem fx:id="w2IV" mnemonicParsing="false" onAction="#w2IV" text="IV" /> - <MenuItem fx:id="w2V" mnemonicParsing="false" onAction="#w2V" text="V" /> - </items> </MenuButton> <!-- <MenuButton layoutX="93.0" layoutY="114.0" mnemonicParsing="false">--> <!-- <items>--> @@ -154,47 +133,31 @@ <!-- <MenuItem mnemonicParsing="false" onAction="#z26" text="26" />--> <!-- </items>--> <!-- </MenuButton>--> - <MenuButton layoutX="173.0" layoutY="114.0" mnemonicParsing="false"> - <items> - <MenuItem mnemonicParsing="false" text="Action 1" /> - <MenuItem mnemonicParsing="false" text="Action 2" /> - </items> + <MenuButton fx:id="r3" layoutX="173.0" layoutY="114.0" mnemonicParsing="false" text="1"> </MenuButton> - <MenuButton layoutX="135.0" layoutY="114.0" mnemonicParsing="false"> - <items> - <MenuItem mnemonicParsing="false" text="Action 1" /> - <MenuItem mnemonicParsing="false" text="Action 2" /> - </items> + <MenuButton fx:id="r2" layoutX="135.0" layoutY="114.0" mnemonicParsing="false" text="1"> </MenuButton> - <MenuButton layoutX="95.0" layoutY="157.0" mnemonicParsing="false"> - <items> - <MenuItem mnemonicParsing="false" text="Action 1" /> - <MenuItem mnemonicParsing="false" text="Action 2" /> - </items> + <MenuButton fx:id="a1" layoutX="95.0" layoutY="157.0" mnemonicParsing="false" text="A"> </MenuButton> - <MenuButton layoutX="175.0" layoutY="157.0" mnemonicParsing="false"> - <items> - <MenuItem mnemonicParsing="false" text="Action 1" /> - <MenuItem mnemonicParsing="false" text="Action 2" /> - </items> + <MenuButton fx:id="a3" layoutX="175.0" layoutY="157.0" mnemonicParsing="false" text="A"> </MenuButton> - <MenuButton layoutX="137.0" layoutY="157.0" mnemonicParsing="false"> - <items> - <MenuItem mnemonicParsing="false" text="Action 1" /> - <MenuItem mnemonicParsing="false" text="Action 2" /> - </items> + <MenuButton fx:id="a2" layoutX="137.0" layoutY="157.0" mnemonicParsing="false" text="A"> </MenuButton> <TextField layoutX="246.0" layoutY="76.0" prefHeight="77.0" prefWidth="410.0" /> <TextField layoutX="248.0" layoutY="182.0" prefHeight="77.0" prefWidth="410.0" /> <Button layoutX="717.0" layoutY="221.0" mnemonicParsing="false" onAction="#btnsenden" prefHeight="69.0" prefWidth="164.0" text="An Funker senden" /> - <Button layoutX="717.0" layoutY="135.0" mnemonicParsing="false" prefHeight="69.0" prefWidth="164.0" text="Funkspruch empfangen" /> + <Button layoutX="717.0" layoutY="135.0" mnemonicParsing="false" onAction="#empfangen" prefHeight="69.0" prefWidth="164.0" text="Funkspruch empfangen" /> <TextField layoutX="725.0" layoutY="76.0" /> <Label layoutX="727.0" layoutY="51.0" prefHeight="17.0" prefWidth="149.0" text="Kenngruppe" /> - <MenuButton layoutX="93.0" layoutY="114.0" mnemonicParsing="false"> + <MenuButton fx:id="r1" layoutX="93.0" layoutY="114.0" mnemonicParsing="false" text="1"> <items> <MenuItem mnemonicParsing="false" text="Action 1" /> <MenuItem mnemonicParsing="false" text="Action 2" /> </items> </MenuButton> + <Label layoutX="29.0" layoutY="80.0" text="Walze" /> + <Label layoutX="29.0" layoutY="127.0" text="Ringe" /> + <Label layoutX="11.0" layoutY="161.0" text="Startposition" /> + <Label layoutX="380.0" layoutY="27.0" prefHeight="17.0" prefWidth="172.0" text="Tageseinstellungen" /> </children> </AnchorPane> -- GitLab