EventHandler && Interface
This commit is contained in:
parent
f297819dc4
commit
a8a04b9275
@ -15,37 +15,36 @@ public class Main extends Application
|
||||
{
|
||||
RootBorderPane root = new RootBorderPane();
|
||||
Scene scene = new Scene(root, 450, 200);
|
||||
|
||||
primaryStage.setTitle("Kontaktanfrage");
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("Kontaktanfrage");
|
||||
primaryStage.show();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
showAlert(AlertType.ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAlert(AlertType alertType, String message)
|
||||
{
|
||||
if (message != null)
|
||||
{
|
||||
Alert alert = new Alert(alertType, message, ButtonType.OK);
|
||||
alert.setHeaderText(null);
|
||||
if (alertType == AlertType.WARNING)
|
||||
alert.setTitle("Warnung");
|
||||
else
|
||||
alert.setTitle("Hinweis-Meldung");
|
||||
alert.showAndWait();
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert alert = new Alert(alertType, "Bitte waehlen Sie \"Weiter\" aus", ButtonType.NEXT);
|
||||
alert.setHeaderText(null);
|
||||
alert.setTitle("Hinweis-Meldung");
|
||||
alert.showAndWait();
|
||||
showAlert(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAlert(String message)
|
||||
{
|
||||
if (message != null)
|
||||
{
|
||||
Alert alert = new Alert(AlertType.INFORMATION, message, ButtonType.OK);
|
||||
alert.setHeaderText(null);
|
||||
alert.setTitle("Hinweis");
|
||||
alert.showAndWait();
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert alert = new Alert(AlertType.INFORMATION, "Bitte mit \"Weiter\" bestaetigen", ButtonType.NEXT);
|
||||
alert.setHeaderText(null);
|
||||
alert.setTitle("Hinweis");
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
launch(args);
|
||||
|
@ -1,10 +1,12 @@
|
||||
package application;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
@ -12,133 +14,201 @@ import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuBar;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.control.SeparatorMenuItem;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.stage.FileChooser;
|
||||
|
||||
public class RootBorderPane extends BorderPane {
|
||||
|
||||
private MenuBar menuBar;
|
||||
public class RootBorderPane extends BorderPane
|
||||
{
|
||||
private MenuBar menubar;
|
||||
private Menu mDatei;
|
||||
private MenuItem miBeenden;
|
||||
|
||||
private Label lbRadios, lbName, lbTelefon, lbSofortKontakt;
|
||||
private RadioButton rbPersoenlich, rbTelefonisch, rbEgal;
|
||||
private TextField tfName, tfTelefonNr;
|
||||
private ToggleGroup toggleGroup;
|
||||
private Button btPruefen, btAbsenden;
|
||||
private CheckBox cbSofort;
|
||||
private TextField tfName, tfTelefonnummer;
|
||||
private Button btPruefen, btSpeichern;
|
||||
private ToggleGroup tgRadios;
|
||||
private GridPane gpZentrum;
|
||||
private HBox hbRadio;
|
||||
private FlowPane fpButton;
|
||||
|
||||
private HBox hBoxRadios;
|
||||
private GridPane gridPaneMitte;
|
||||
private FlowPane flowPaneUntenButtons;
|
||||
|
||||
public RootBorderPane() {
|
||||
public RootBorderPane()
|
||||
{
|
||||
initComponents();
|
||||
addComponents();
|
||||
addHandler();
|
||||
addHandlers();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
|
||||
menuBar = new MenuBar();
|
||||
private void initComponents()
|
||||
{
|
||||
menubar = new MenuBar();
|
||||
mDatei = new Menu("Datei");
|
||||
miBeenden = new MenuItem("Beenden");
|
||||
|
||||
|
||||
lbRadios = new Label("Art der Kontaktaufnahme:");
|
||||
lbName = new Label("Name:");
|
||||
lbTelefon = new Label("Telefonnummer:");
|
||||
lbSofortKontakt = new Label("Sofortige Kontaktaufnahme:");
|
||||
|
||||
tfName = new TextField();
|
||||
tfName.setPromptText("Bitte Ihren Namen eingeben");
|
||||
tfTelefonnummer = new TextField();
|
||||
tfTelefonnummer.setPromptText("Bitte Ihre Telefonnummer eingeben");
|
||||
|
||||
tfName.setPromptText("Bitte Ihren Namen eingeben...");
|
||||
tfTelefonNr = new TextField();
|
||||
tfTelefonNr.setPromptText("Bitte Ihre Telefonummer eingeben...");
|
||||
|
||||
rbPersoenlich = new RadioButton("persoenlich");
|
||||
rbTelefonisch = new RadioButton("telefonisch");
|
||||
rbEgal = new RadioButton("egal");
|
||||
|
||||
cbSofort = new CheckBox("(binnen eines Tages)");
|
||||
|
||||
gpZentrum = new GridPane();
|
||||
gpZentrum.setHgap(5);
|
||||
gpZentrum.setVgap(5);
|
||||
gpZentrum.setPadding(new Insets(5));
|
||||
|
||||
hbRadio = new HBox(5);
|
||||
toggleGroup = new ToggleGroup();
|
||||
|
||||
fpButton = new FlowPane();
|
||||
fpButton.setHgap(5);
|
||||
fpButton.setPadding(new Insets(5));
|
||||
btPruefen = new Button("Pruefen...");
|
||||
btAbsenden = new Button("Speichern und absenden...");
|
||||
|
||||
btPruefen = new Button("Pruefen");
|
||||
btSpeichern = new Button("Speichern und absenden");
|
||||
|
||||
tgRadios = new ToggleGroup();
|
||||
hBoxRadios = new HBox(5);
|
||||
|
||||
}
|
||||
gridPaneMitte = new GridPane();
|
||||
gridPaneMitte.setVgap(5);
|
||||
gridPaneMitte.setHgap(5);
|
||||
gridPaneMitte.setPadding(new Insets(5));
|
||||
|
||||
private void addComponents() {
|
||||
mDatei.getItems().addAll(miBeenden);
|
||||
menuBar.getMenus().addAll(mDatei);
|
||||
|
||||
gpZentrum.add(new Label("Art der Kontaktaufnahme:"), 0, 0);
|
||||
gpZentrum.add(new Label("Name:"), 0, 1);
|
||||
gpZentrum.add(new Label("Telefonnummer:"), 0, 2);
|
||||
gpZentrum.add(new Label("Sofortige Kontaktaufnahme:"), 0, 3);
|
||||
// gpZentrum.add(new Label("(binnen eines Tages)"), 2, 3);
|
||||
|
||||
gpZentrum.add(hbRadio, 1, 0);
|
||||
gpZentrum.add(cbSofort, 1, 3);
|
||||
|
||||
gpZentrum.add(tfName, 1, 1);
|
||||
gpZentrum.add(tfTelefonnummer, 1, 2);
|
||||
|
||||
// GridPane.setColumnSpan(tfName, 3);
|
||||
// GridPane.setColumnSpan(tfTelefonnummer, 3);
|
||||
|
||||
tgRadios.getToggles().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
||||
|
||||
hbRadio.getChildren().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
||||
|
||||
fpButton.getChildren().addAll(btPruefen, btSpeichern);
|
||||
|
||||
setTop(menuBar);
|
||||
setCenter(gpZentrum);
|
||||
setBottom(fpButton);
|
||||
|
||||
flowPaneUntenButtons = new FlowPane();
|
||||
flowPaneUntenButtons.setHgap(5);
|
||||
flowPaneUntenButtons.setPadding(new Insets(5));
|
||||
}
|
||||
|
||||
private void addHandler() {
|
||||
miBeenden.setOnAction(event -> beenden());
|
||||
btPruefen.setOnAction(Event -> pruefen());
|
||||
// TODO Speichern
|
||||
}
|
||||
|
||||
// ---------------------- handlers -----------------------
|
||||
|
||||
private void beenden() {
|
||||
private void addComponents()
|
||||
{
|
||||
menubar.getMenus().addAll(mDatei);
|
||||
mDatei.getItems().addAll(miBeenden);
|
||||
|
||||
hBoxRadios.getChildren().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
||||
|
||||
toggleGroup.getToggles().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
||||
|
||||
gridPaneMitte.add(lbRadios, 0, 0);
|
||||
gridPaneMitte.add(lbName, 0, 1);
|
||||
gridPaneMitte.add(lbTelefon, 0, 2);
|
||||
gridPaneMitte.add(lbSofortKontakt, 0, 3);
|
||||
|
||||
gridPaneMitte.add(hBoxRadios, 1, 0);
|
||||
gridPaneMitte.add(tfName, 1, 1);
|
||||
gridPaneMitte.add(tfTelefonNr, 1, 2);
|
||||
gridPaneMitte.add(cbSofort, 1, 3);
|
||||
|
||||
flowPaneUntenButtons.getChildren().addAll(btPruefen, btAbsenden);
|
||||
|
||||
setTop(menubar);
|
||||
setCenter(gridPaneMitte);
|
||||
setBottom(flowPaneUntenButtons);
|
||||
}
|
||||
|
||||
private void addHandlers()
|
||||
{
|
||||
miBeenden.setOnAction(event -> beenden());
|
||||
btPruefen.setOnAction(event -> pruefen());
|
||||
btAbsenden.setOnAction(event -> absenden());
|
||||
}
|
||||
// -------------------------- Handler - Methoden -----------------------------
|
||||
private void pruefen()
|
||||
{
|
||||
String text;
|
||||
if (checkEingaben() && !checkSofortPersoenlich())
|
||||
text = "Die Pruefung war erfolgreich. Die Eingaben der Kontaktanfrage sind in Ordnung.";
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder("Folgende Eingaben fehlen:\n");
|
||||
if (!checkEingaben())
|
||||
{
|
||||
if (!rbPersoenlich.isSelected()&&!rbTelefonisch.isSelected()&&!rbEgal.isSelected())
|
||||
sb.append("Art der Kontaktaufnahme\n");
|
||||
if (tfName.getText().isEmpty())
|
||||
sb.append("Name\n");
|
||||
if (tfTelefonNr.getText().isEmpty())
|
||||
sb.append("Telefonnummer");
|
||||
text = sb.toString();
|
||||
}
|
||||
else
|
||||
text = "Sofortige persoenliche Kontaktaufnahmen sollten derzeit wegen langer Wartezeiten nicht abgesendet werden";
|
||||
}
|
||||
Main.showAlert(text);
|
||||
}
|
||||
|
||||
private void absenden()
|
||||
{
|
||||
if (checkEingaben())
|
||||
{
|
||||
FileChooser fc = new FileChooser();
|
||||
File selected = fc.showSaveDialog(null);
|
||||
String textSpeichern;
|
||||
if (selected != null)
|
||||
{
|
||||
String pfadDateiName = selected.getAbsolutePath();
|
||||
speichern(selected);
|
||||
textSpeichern = "Ihre Kundenanfrage wurde unter " + pfadDateiName +
|
||||
" gespeichert\n";
|
||||
}
|
||||
else
|
||||
textSpeichern = "Ihre Kundenanfrage wurde nicht gespeichert\n";
|
||||
Main.showAlert(textSpeichern);
|
||||
|
||||
StringBuilder sb = new StringBuilder(tfName.getText()).
|
||||
append(", danke fuer Ihre Anfrage!\n").
|
||||
append("Unser Kundenservice wird sich bei Ihnen melden\n");
|
||||
if (cbSofort.isSelected())
|
||||
sb.append("Derzeit gibt es laengere Wartezeiten, danke f<>r Ihre Geduld!");
|
||||
Main.showAlert(sb.toString());
|
||||
Platform.exit();
|
||||
}
|
||||
else
|
||||
Main.showAlert("Pruefen Sie bitte die Eingaben: Art der Kontaktaufnahme, Name und Telefonnummer werden benoetigt");
|
||||
}
|
||||
|
||||
private void speichern(File selected)
|
||||
{
|
||||
if (selected != null)
|
||||
{
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(selected)))
|
||||
{
|
||||
// Rosa Munde;01/545 45 45
|
||||
String separator = ";";
|
||||
bw.write(tfName.getText() + separator + tfTelefonNr.getText());
|
||||
} catch (IOException e) {
|
||||
Main.showAlert(e.getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
Main.showAlert("Fehler beim Speichern: null-Referenz fuer Datei erhalten");
|
||||
}
|
||||
|
||||
private void beenden()
|
||||
{
|
||||
Platform.exit();
|
||||
}
|
||||
|
||||
private void pruefen() {
|
||||
String name = tfName.getText();
|
||||
String tel = tfTelefonnummer.getText();
|
||||
|
||||
try {
|
||||
if(name.isEmpty() | tel.isEmpty() | tgRadios.getSelectedToggle() == null) {
|
||||
Main.showAlert(AlertType.INFORMATION, "Pruefen Sie bitte die Eingaben: Art der Kontaktaufnahme, Name und Telefonnummer werden benoetigt");
|
||||
} else {
|
||||
if(rbPersoenlich.isSelected() & cbSofort.isSelected()) {
|
||||
Main.showAlert(AlertType.INFORMATION, "Sofortige persoenliche Kontaktaufnahmen sollten derzeit wegen langer Wartezeiten nicht abgesendet werden");
|
||||
} else {
|
||||
Main.showAlert(AlertType.INFORMATION, "Die Pruefung war erfolgreich. Die Eingaben der Kontaktanfrage sind in Ordnung");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
Main.showAlert(AlertType.ERROR, e.getMessage());
|
||||
}
|
||||
// -------------------------- Hilfsmethoden -----------------------------------
|
||||
private boolean checkSofortPersoenlich()
|
||||
{
|
||||
if (cbSofort.isSelected() && rbPersoenlich.isSelected())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkEingaben()
|
||||
{
|
||||
if (tfName.getText()!="" &&
|
||||
tfTelefonNr.getText()!="" &&
|
||||
(rbPersoenlich.isSelected() || rbTelefonisch.isSelected() || rbEgal.isSelected()))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user