diff options
Diffstat (limited to 'Java-Kompendium/kap14/1/src/main/java/EnterHandler.java')
| -rw-r--r-- | Java-Kompendium/kap14/1/src/main/java/EnterHandler.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Java-Kompendium/kap14/1/src/main/java/EnterHandler.java b/Java-Kompendium/kap14/1/src/main/java/EnterHandler.java new file mode 100644 index 0000000..f612707 --- /dev/null +++ b/Java-Kompendium/kap14/1/src/main/java/EnterHandler.java @@ -0,0 +1,31 @@ +import java.io.*; + +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.control.Alert; +import javafx.scene.control.TextField; +import javafx.scene.control.Alert.AlertType; + +public final class EnterHandler implements EventHandler<ActionEvent> { + private BufferedWriter outputStream; + private TextField inputField; + + public EnterHandler(TextField input, BufferedWriter output) { + this.outputStream = output; + this.inputField = input; + } + + public void handle(ActionEvent event) { + Alert alert; + try { + this.outputStream.write(inputField.getText() + "\n"); + } catch (IOException exception) { + alert = new Alert(AlertType.ERROR, exception.getMessage()); + alert.showAndWait(); + return; + } + alert = new Alert(AlertType.INFORMATION, "Gespeichert"); + alert.showAndWait(); + inputField.setText(""); + } +} |
