From e2de2b738300771a013809e3198e22d885a3b600 Mon Sep 17 00:00:00 2001 From: Kevin Pfannenstiel Date: Tue, 31 Jan 2023 15:49:57 +0100 Subject: [PATCH] Fehler behoben --- order.txt | 0 .../java/com/example/vpr_javafx/Data.java | 9 +- .../example/vpr_javafx/HelloController.java | 209 +++++++++++++++--- .../example/vpr_javafx/MenuOverview-view.fxml | 92 ++++---- .../classes/com/example/vpr_javafx/Data.class | Bin 10353 -> 10522 bytes .../example/vpr_javafx/HelloController.class | Bin 5078 -> 10189 bytes .../example/vpr_javafx/MenuOverview-view.fxml | 92 ++++---- 7 files changed, 296 insertions(+), 106 deletions(-) create mode 100644 order.txt diff --git a/order.txt b/order.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/example/vpr_javafx/Data.java b/src/main/java/com/example/vpr_javafx/Data.java index b2f9189..aea4a35 100644 --- a/src/main/java/com/example/vpr_javafx/Data.java +++ b/src/main/java/com/example/vpr_javafx/Data.java @@ -287,7 +287,7 @@ public class Data { * @return boolean inputValid * @author Kevin Maier, Kevin Pfannenstiel */ - public boolean validateData(TextField tfPhone, PasswordField pfPassword) + public boolean validateData(TextField tfPhone, PasswordField pfPassword, HelloController controller) { boolean phoneNumberMatchFound; boolean passwordMatchFound; @@ -305,7 +305,7 @@ public class Data { if (password.isEmpty() || phoneNumber.isEmpty()) { Alert alert = new Alert(Alert.AlertType.WARNING); - alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide."); + alert.setContentText("Login fehlgeschlagen. Es wurde nichts eingegeben."); alert.show(); return false; } @@ -319,7 +319,7 @@ public class Data { if (!users.containsKey(phoneNumber) || !phoneNumberMatchFound || phoneNumber.length() >= 15) { Alert alert = new Alert(Alert.AlertType.WARNING); - alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide."); + alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch."); alert.show(); return false; } @@ -331,13 +331,14 @@ public class Data { if (!users.get(phoneNumber).equals(password) || !passwordMatchFound || password.length() <8) { Alert alert = new Alert(Alert.AlertType.WARNING); - alert.setContentText("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide."); + alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch."); alert.show(); return false; } else { passwordValid = true; + controller.setRadioButton(); } return phoneNumberValid && passwordValid; diff --git a/src/main/java/com/example/vpr_javafx/HelloController.java b/src/main/java/com/example/vpr_javafx/HelloController.java index 6e530dd..62df7ee 100644 --- a/src/main/java/com/example/vpr_javafx/HelloController.java +++ b/src/main/java/com/example/vpr_javafx/HelloController.java @@ -9,6 +9,7 @@ import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; import java.io.Console; @@ -17,6 +18,7 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -83,6 +85,8 @@ public class HelloController { private ImageView imgImage9; @FXML private ImageView imgImage10; + @FXML + private AnchorPane anchorPane; @FXML private TextField tfPhone; @@ -96,9 +100,30 @@ public class HelloController { @FXML private Label allergene; - private Stage stage; - private Scene scene; - + @FXML + private Button btResetSelection; + @FXML + private Button btToOrder; + @FXML + private RadioButton rbMonH1; + @FXML + private RadioButton rbMonH2; + @FXML + private RadioButton rbTueH1; + @FXML + private RadioButton rbTueH2; + @FXML + private RadioButton rbWednH1; + @FXML + private RadioButton rbWednH2; + @FXML + private RadioButton rbThurH1; + @FXML + private RadioButton rbThurH2; + @FXML + private RadioButton rbFriH1; + @FXML + private RadioButton rbFriH2; @FXML @@ -110,17 +135,18 @@ public class HelloController { @FXML private String imageUrl; + private ArrayList chosenMeals; + @FXML protected void OnSignInButton(ActionEvent event) throws IOException { - Data data = new Data("user.txt"); - data.validateData(tfPhone, pfPassword); + Data data = new Data("user.txt"); + data.validateData(tfPhone, pfPassword, this); } @FXML protected void FillLabels() { - try { List menu = Files.readAllLines(Paths.get("menue.txt")); @@ -136,85 +162,85 @@ public class HelloController { String dayMenu = dish+"\n"+sideDish+"\n"+"("+allergenic+")"; -// if(typ.equals("Fleisch")) { -// imageUrl=meatUrl; -// } -// if(typ.equals("Vegetarisch")) { -// imageUrl=veggieImageUrl; -// } -// if(typ.equals("Vegan")) { -// imageUrl=veganUrl; -// } -// -// Image image = new Image("C:/Unterricht/VPR_Projekt/target/classes/com/example/vpr_javafx/" + imageUrl); + if(typ.equals("Fleisch")) { + imageUrl=meatUrl; + } + if(typ.equals("Vegetarisch")) { + imageUrl=veggieImageUrl; + } + if(typ.equals("Vegan")) { + imageUrl=veganUrl; + } + + Image image = new Image("C:/VPR_Projekt_Java/target/classes/com/example/vpr_javafx/" + imageUrl); switch (i) { case 0: lMonH1.setText(dayMenu); -// imgImage1.setImage(image); + imgImage1.setImage(image); break; case 1: lMonD1.setText(dayMenu); break; case 2: lMonH2.setText(dayMenu); -// imgImage2.setImage(image); + imgImage2.setImage(image); break; case 3: lMonD2.setText(dayMenu); break; case 4: lTueH1.setText(dayMenu); -// imgImage3.setImage(image); + imgImage3.setImage(image); break; case 5: lTueD1.setText(dayMenu); break; case 6: lTueH2.setText(dayMenu); -// imgImage4.setImage(image); + imgImage4.setImage(image); break; case 7: lTueD2.setText(dayMenu); break; case 8: lWednH1.setText(dayMenu); -// imgImage5.setImage(image); + imgImage5.setImage(image); break; case 9: lWednD1.setText(dayMenu); break; case 10: lWednH2.setText(dayMenu); -// imgImage6.setImage(image); + imgImage6.setImage(image); break; case 11: lWednD2.setText(dayMenu); break; case 12: lThurH1.setText(dayMenu); -// imgImage7.setImage(image); + imgImage7.setImage(image); break; case 13: lThurD1.setText(dayMenu); break; case 14: lThurH2.setText(dayMenu); -// imgImage8.setImage(image); + imgImage8.setImage(image); break; case 15: lThurD2.setText(dayMenu); break; case 16: lFriH1.setText(dayMenu); -// imgImage9.setImage(image); + imgImage9.setImage(image); break; case 17: lFriD1.setText(dayMenu); break; case 18: lFriH2.setText(dayMenu); -// imgImage10.setImage(image); + imgImage10.setImage(image); break; case 19: lFriD2.setText(dayMenu); @@ -261,7 +287,7 @@ public class HelloController { { alert.setContentText("Registrierungsdaten unvollständig"); } - else if (validData.validateData(tfPhone, pfPassword)) + else if (validData.validateData(tfPhone, pfPassword, this)) { try (FileWriter writer = new FileWriter("user.txt")){ writer.write(tfName.getText() + ";" + tfPhone.getText() + ";" + tfChild.getText() + ";" + pfPassword.getText()); @@ -273,4 +299,131 @@ public class HelloController { } } } + + @FXML + protected void setRadioButton() + { + ToggleGroup monToggle = new ToggleGroup(); + ToggleGroup tueToggle = new ToggleGroup(); + ToggleGroup wednToggle = new ToggleGroup(); + ToggleGroup thurToggle = new ToggleGroup(); + ToggleGroup friToggle = new ToggleGroup(); + + rbMonH1.setToggleGroup(monToggle); + rbMonH2.setToggleGroup(monToggle); + rbTueH1.setToggleGroup(tueToggle); + rbTueH2.setToggleGroup(tueToggle); + rbWednH1.setToggleGroup(wednToggle); + rbWednH2.setToggleGroup(wednToggle); + rbThurH1.setToggleGroup(thurToggle); + rbThurH2.setToggleGroup(thurToggle); + rbFriH1.setToggleGroup(friToggle); + rbFriH1.setToggleGroup(friToggle); + + btResetSelection.setVisible(true); + btToOrder.setVisible(true); + rbMonH1.setVisible(true); + rbMonH2.setVisible(true); + rbTueH1.setVisible(true); + rbTueH2.setVisible(true); + rbWednH1.setVisible(true); + rbWednH2.setVisible(true); + rbThurH1.setVisible(true); + rbThurH2.setVisible(true); + rbFriH1.setVisible(true); + rbFriH2.setVisible(true); + + } + + @FXML + protected void resetSelection(ActionEvent event) throws IOException + { + rbMonH1.setSelected(false); + rbMonH2.setSelected(false); + rbTueH1.setSelected(false); + rbTueH2.setSelected(false); + rbWednH1.setSelected(false); + rbWednH2.setSelected(false); + rbThurH1.setSelected(false); + rbThurH2.setSelected(false); + rbFriH1.setSelected(false); + rbFriH2.setSelected(false); + chosenMeals.clear(); + } + + + @FXML + protected void getLabelValueWithRadio(ActionEvent event) + { + chosenMeals = new ArrayList<>(); + String mainDish; + String dessert; + + if (rbMonH1.isSelected()) + { + mainDish = lMonH1.getText(); + dessert = lMonD1.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + + } + if (rbMonH2.isSelected()) + { + mainDish = lMonH2.getText(); + dessert = lMonD2.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbTueH1.isSelected()) + { + mainDish = lTueH1.getText(); + dessert = lTueD1.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbTueH2.isSelected()) + { + mainDish = lTueH2.getText(); + dessert = lTueD2.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbWednH1.isSelected()) + { + mainDish = lWednH1.getText(); + dessert = lWednD1.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbWednH2.isSelected()) + { + mainDish = lWednH2.getText(); + dessert = lWednD2.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbThurH1.isSelected()) + { + mainDish = lThurH1.getText(); + dessert = lThurD1.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbThurH2.isSelected()) + { + mainDish = lThurH2.getText(); + dessert = lThurD2.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbFriH1.isSelected()) + { + mainDish = lFriH1.getText(); + dessert = lFriD1.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + if (rbFriH2.isSelected()) + { + mainDish = lFriH2.getText(); + dessert = lFriD2.getText(); + chosenMeals.add("Hauptgericht: " + mainDish + " Dessert: " + dessert); + } + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setContentText(chosenMeals.toString()); + alert.show(); + } + + } \ No newline at end of file diff --git a/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml b/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml index d2c88f8..83b1fdf 100644 --- a/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml +++ b/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml @@ -1,19 +1,14 @@ - - - - - - - - - - - + + + + + + - -