276 lines
7.7 KiB
Java
Raw Normal View History

2023-01-25 10:30:40 +01:00
package com.example.vpr_javafx;
import javafx.event.ActionEvent;
2023-01-25 10:30:40 +01:00
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import java.io.Console;
import java.io.File;
2023-01-31 14:57:37 +01:00
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
2023-01-25 10:30:40 +01:00
public class HelloController {
2023-01-31 14:57:37 +01:00
2023-01-25 10:30:40 +01:00
@FXML
private Label lMonH1;
@FXML
private Label lMonH2;
@FXML
private Label lMonD1;
@FXML
private Label lMonD2;
@FXML
private Label lTueH1;
@FXML
private Label lTueH2;
@FXML
private Label lTueD1;
@FXML
private Label lTueD2;
@FXML
private Label lWednH1;
@FXML
private Label lWednH2;
@FXML
private Label lWednD1;
@FXML
private Label lWednD2;
@FXML
private Label lThurH1;
@FXML
private Label lThurH2;
@FXML
private Label lThurD1;
@FXML
private Label lThurD2;
@FXML
private Label lFriH1;
@FXML
private Label lFriH2;
@FXML
private Label lFriD1;
@FXML
private Label lFriD2;
2023-01-25 10:30:40 +01:00
@FXML
private ImageView imgImage1;
@FXML
private ImageView imgImage2;
@FXML
private ImageView imgImage3;
@FXML
private ImageView imgImage4;
@FXML
private ImageView imgImage5;
@FXML
private ImageView imgImage6;
@FXML
private ImageView imgImage7;
@FXML
private ImageView imgImage8;
@FXML
private ImageView imgImage9;
@FXML
private ImageView imgImage10;
2023-01-25 10:30:40 +01:00
@FXML
private TextField tfPhone;
2023-01-31 14:57:37 +01:00
@FXML
public TextField tfName;
@FXML
public TextField tfChild;
@FXML
private PasswordField pfPassword;
2023-01-30 15:10:54 +01:00
@FXML
private Label allergene;
private Stage stage;
private Scene scene;
2023-01-30 15:10:54 +01:00
@FXML
private String veggieImageUrl = "pics/vegetarisch.png";
@FXML
private String veganUrl = "pics/vegan.png";
@FXML
private String meatUrl = "pics/fleisch.png";
@FXML
private String imageUrl;
@FXML
protected void OnSignInButton(ActionEvent event) throws IOException
{
2023-01-30 15:10:54 +01:00
Data data = new Data("user.txt");
data.validateData(tfPhone, pfPassword);
2023-01-30 14:33:30 +01:00
}
@FXML
protected void FillLabels() {
2023-01-31 14:27:24 +01:00
try {
2023-01-30 14:33:30 +01:00
List<String> menu = Files.readAllLines(Paths.get("menue.txt"));
2023-01-30 14:33:30 +01:00
for (int i = 0; i < menu.size(); i++)
{
2023-01-30 14:33:30 +01:00
String[] parts = menu.get(i).split(";");
String dish = parts[1];
String sideDish = parts[2];
String typ = parts[3];
String allergenic = parts[4];
String dayMenu = dish+"\n"+sideDish+"\n"+"("+allergenic+")";
2023-01-31 14:27:24 +01:00
// 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);
2023-01-30 14:33:30 +01:00
switch (i) {
case 0:
lMonH1.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage1.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 1:
lMonD1.setText(dayMenu);
break;
case 2:
lMonH2.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage2.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 3:
lMonD2.setText(dayMenu);
break;
case 4:
lTueH1.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage3.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 5:
lTueD1.setText(dayMenu);
break;
case 6:
lTueH2.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage4.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 7:
lTueD2.setText(dayMenu);
break;
case 8:
lWednH1.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage5.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 9:
lWednD1.setText(dayMenu);
break;
case 10:
lWednH2.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage6.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 11:
lWednD2.setText(dayMenu);
break;
case 12:
lThurH1.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage7.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 13:
lThurD1.setText(dayMenu);
break;
case 14:
lThurH2.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage8.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 15:
lThurD2.setText(dayMenu);
break;
case 16:
lFriH1.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage9.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 17:
lFriD1.setText(dayMenu);
break;
case 18:
lFriH2.setText(dayMenu);
2023-01-31 14:27:24 +01:00
// imgImage10.setImage(image);
2023-01-30 14:33:30 +01:00
break;
case 19:
lFriD2.setText(dayMenu);
break;
}
}
}
2023-01-30 14:33:30 +01:00
catch (IOException e) {
e.printStackTrace();
}
}
2023-01-30 14:33:30 +01:00
/**
* writeAllergene() is a method to format and set allergene
* @author Madeleine Vigier
*/
@FXML
protected void writeAllergene() {
allergene.setText("a: Eier; b: Soja,\n"
+ "c: Milch; d: Erdnüsse;\n"
+ "e: Weichtiere; f: Krebstiere;\n"
+ "g: Getreide; h: Senf; i: Sesam;\n"
+ "j: Schwefeldioxid und Sulfit;\n"
+ "k: Nüsse; l: Sellerie;\n"
+ "m: Fische; n: Lupinen\n\n"
+ "1: Nitrit-Pökelsalz\n"
2023-01-31 14:57:37 +01:00
+ "2: Phosphat\n"
2023-01-30 14:33:30 +01:00
+ "3: Nitrat\n"
+ "4: Antioxidationsmittel\n"
+ "5: Farbstoff\n"
+ "6: Geschmacksverstärker;\n"
+ "7: Süßungsmittel;\n"
+ "8: Konservierungsstoff");
2023-01-25 10:30:40 +01:00
}
2023-01-30 14:33:30 +01:00
2023-01-31 14:57:37 +01:00
@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();
}
}
}
2023-01-25 10:30:40 +01:00
}