EventHandler && Interface
This commit is contained in:
parent
f297819dc4
commit
a8a04b9275
@ -15,33 +15,32 @@ public class Main extends Application
|
|||||||
{
|
{
|
||||||
RootBorderPane root = new RootBorderPane();
|
RootBorderPane root = new RootBorderPane();
|
||||||
Scene scene = new Scene(root, 450, 200);
|
Scene scene = new Scene(root, 450, 200);
|
||||||
|
|
||||||
|
primaryStage.setTitle("Kontaktanfrage");
|
||||||
|
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.setTitle("Kontaktanfrage");
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
showAlert(AlertType.ERROR, e.getMessage());
|
showAlert(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showAlert(AlertType alertType, String message)
|
public static void showAlert(String message)
|
||||||
{
|
{
|
||||||
if (message != null)
|
if (message != null)
|
||||||
{
|
{
|
||||||
Alert alert = new Alert(alertType, message, ButtonType.OK);
|
Alert alert = new Alert(AlertType.INFORMATION, message, ButtonType.OK);
|
||||||
alert.setHeaderText(null);
|
alert.setHeaderText(null);
|
||||||
if (alertType == AlertType.WARNING)
|
alert.setTitle("Hinweis");
|
||||||
alert.setTitle("Warnung");
|
|
||||||
else
|
|
||||||
alert.setTitle("Hinweis-Meldung");
|
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Alert alert = new Alert(alertType, "Bitte waehlen Sie \"Weiter\" aus", ButtonType.NEXT);
|
Alert alert = new Alert(AlertType.INFORMATION, "Bitte mit \"Weiter\" bestaetigen", ButtonType.NEXT);
|
||||||
alert.setHeaderText(null);
|
alert.setHeaderText(null);
|
||||||
alert.setTitle("Hinweis-Meldung");
|
alert.setTitle("Hinweis");
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package application;
|
package application;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.geometry.HPos;
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.geometry.VPos;
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.CheckBox;
|
import javafx.scene.control.CheckBox;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@ -12,47 +14,53 @@ import javafx.scene.control.Menu;
|
|||||||
import javafx.scene.control.MenuBar;
|
import javafx.scene.control.MenuBar;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.control.RadioButton;
|
import javafx.scene.control.RadioButton;
|
||||||
import javafx.scene.control.SeparatorMenuItem;
|
|
||||||
import javafx.scene.control.TextArea;
|
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.ToggleGroup;
|
import javafx.scene.control.ToggleGroup;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.FlowPane;
|
import javafx.scene.layout.FlowPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
|
||||||
public class RootBorderPane extends BorderPane {
|
public class RootBorderPane extends BorderPane
|
||||||
|
{
|
||||||
private MenuBar menuBar;
|
private MenuBar menubar;
|
||||||
private Menu mDatei;
|
private Menu mDatei;
|
||||||
private MenuItem miBeenden;
|
private MenuItem miBeenden;
|
||||||
private RadioButton rbPersoenlich, rbTelefonisch, rbEgal;
|
|
||||||
private CheckBox cbSofort;
|
|
||||||
private TextField tfName, tfTelefonnummer;
|
|
||||||
private Button btPruefen, btSpeichern;
|
|
||||||
private ToggleGroup tgRadios;
|
|
||||||
private GridPane gpZentrum;
|
|
||||||
private HBox hbRadio;
|
|
||||||
private FlowPane fpButton;
|
|
||||||
|
|
||||||
public RootBorderPane() {
|
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 HBox hBoxRadios;
|
||||||
|
private GridPane gridPaneMitte;
|
||||||
|
private FlowPane flowPaneUntenButtons;
|
||||||
|
|
||||||
|
public RootBorderPane()
|
||||||
|
{
|
||||||
initComponents();
|
initComponents();
|
||||||
addComponents();
|
addComponents();
|
||||||
addHandler();
|
addHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initComponents() {
|
private void initComponents()
|
||||||
|
{
|
||||||
menuBar = new MenuBar();
|
menubar = new MenuBar();
|
||||||
mDatei = new Menu("Datei");
|
mDatei = new Menu("Datei");
|
||||||
miBeenden = new MenuItem("Beenden");
|
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 = new TextField();
|
||||||
tfName.setPromptText("Bitte Ihren Namen eingeben");
|
tfName.setPromptText("Bitte Ihren Namen eingeben...");
|
||||||
tfTelefonnummer = new TextField();
|
tfTelefonNr = new TextField();
|
||||||
tfTelefonnummer.setPromptText("Bitte Ihre Telefonnummer eingeben");
|
tfTelefonNr.setPromptText("Bitte Ihre Telefonummer eingeben...");
|
||||||
|
|
||||||
rbPersoenlich = new RadioButton("persoenlich");
|
rbPersoenlich = new RadioButton("persoenlich");
|
||||||
rbTelefonisch = new RadioButton("telefonisch");
|
rbTelefonisch = new RadioButton("telefonisch");
|
||||||
@ -60,85 +68,147 @@ public class RootBorderPane extends BorderPane {
|
|||||||
|
|
||||||
cbSofort = new CheckBox("(binnen eines Tages)");
|
cbSofort = new CheckBox("(binnen eines Tages)");
|
||||||
|
|
||||||
gpZentrum = new GridPane();
|
toggleGroup = new ToggleGroup();
|
||||||
gpZentrum.setHgap(5);
|
|
||||||
gpZentrum.setVgap(5);
|
|
||||||
gpZentrum.setPadding(new Insets(5));
|
|
||||||
|
|
||||||
hbRadio = new HBox(5);
|
btPruefen = new Button("Pruefen...");
|
||||||
|
btAbsenden = new Button("Speichern und absenden...");
|
||||||
|
|
||||||
fpButton = new FlowPane();
|
hBoxRadios = new HBox(5);
|
||||||
fpButton.setHgap(5);
|
|
||||||
fpButton.setPadding(new Insets(5));
|
|
||||||
|
|
||||||
btPruefen = new Button("Pruefen");
|
gridPaneMitte = new GridPane();
|
||||||
btSpeichern = new Button("Speichern und absenden");
|
gridPaneMitte.setVgap(5);
|
||||||
|
gridPaneMitte.setHgap(5);
|
||||||
tgRadios = new ToggleGroup();
|
gridPaneMitte.setPadding(new Insets(5));
|
||||||
|
|
||||||
|
flowPaneUntenButtons = new FlowPane();
|
||||||
|
flowPaneUntenButtons.setHgap(5);
|
||||||
|
flowPaneUntenButtons.setPadding(new Insets(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addComponents() {
|
private void addComponents()
|
||||||
|
{
|
||||||
|
menubar.getMenus().addAll(mDatei);
|
||||||
mDatei.getItems().addAll(miBeenden);
|
mDatei.getItems().addAll(miBeenden);
|
||||||
menuBar.getMenus().addAll(mDatei);
|
|
||||||
|
|
||||||
gpZentrum.add(new Label("Art der Kontaktaufnahme:"), 0, 0);
|
hBoxRadios.getChildren().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
||||||
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);
|
toggleGroup.getToggles().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
||||||
gpZentrum.add(cbSofort, 1, 3);
|
|
||||||
|
|
||||||
gpZentrum.add(tfName, 1, 1);
|
gridPaneMitte.add(lbRadios, 0, 0);
|
||||||
gpZentrum.add(tfTelefonnummer, 1, 2);
|
gridPaneMitte.add(lbName, 0, 1);
|
||||||
|
gridPaneMitte.add(lbTelefon, 0, 2);
|
||||||
|
gridPaneMitte.add(lbSofortKontakt, 0, 3);
|
||||||
|
|
||||||
// GridPane.setColumnSpan(tfName, 3);
|
gridPaneMitte.add(hBoxRadios, 1, 0);
|
||||||
// GridPane.setColumnSpan(tfTelefonnummer, 3);
|
gridPaneMitte.add(tfName, 1, 1);
|
||||||
|
gridPaneMitte.add(tfTelefonNr, 1, 2);
|
||||||
|
gridPaneMitte.add(cbSofort, 1, 3);
|
||||||
|
|
||||||
tgRadios.getToggles().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
flowPaneUntenButtons.getChildren().addAll(btPruefen, btAbsenden);
|
||||||
|
|
||||||
hbRadio.getChildren().addAll(rbPersoenlich, rbTelefonisch, rbEgal);
|
|
||||||
|
|
||||||
fpButton.getChildren().addAll(btPruefen, btSpeichern);
|
|
||||||
|
|
||||||
setTop(menuBar);
|
|
||||||
setCenter(gpZentrum);
|
|
||||||
setBottom(fpButton);
|
|
||||||
|
|
||||||
|
setTop(menubar);
|
||||||
|
setCenter(gridPaneMitte);
|
||||||
|
setBottom(flowPaneUntenButtons);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHandler() {
|
private void addHandlers()
|
||||||
|
{
|
||||||
miBeenden.setOnAction(event -> beenden());
|
miBeenden.setOnAction(event -> beenden());
|
||||||
btPruefen.setOnAction(Event -> pruefen());
|
btPruefen.setOnAction(event -> pruefen());
|
||||||
// TODO Speichern
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- handlers -----------------------
|
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);
|
||||||
|
|
||||||
private void beenden() {
|
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();
|
Platform.exit();
|
||||||
}
|
}
|
||||||
|
// -------------------------- Hilfsmethoden -----------------------------------
|
||||||
private void pruefen() {
|
private boolean checkSofortPersoenlich()
|
||||||
String name = tfName.getText();
|
{
|
||||||
String tel = tfTelefonnummer.getText();
|
if (cbSofort.isSelected() && rbPersoenlich.isSelected())
|
||||||
|
return true;
|
||||||
try {
|
else
|
||||||
if(name.isEmpty() | tel.isEmpty() | tgRadios.getSelectedToggle() == null) {
|
return false;
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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