summaryrefslogtreecommitdiff
path: root/Java-Kompendium/kap14/1/src/main/java/Task1.java
blob: 14ced3a4fc0c612dc5bf836acf3a8b9de8bd4211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.*;

import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;

public class Task1 extends Application {
    BufferedWriter output = null;

    @Override
    public void start(Stage stage) {
        var userInput = new TextField();
        var root = new StackPane(userInput);
        var scene = new Scene(root, 400, 300);

        stage.setTitle("Geben Sie Ihre Notiz ein:");
        stage.setScene(scene);

        try {
            this.output = new BufferedWriter(new FileWriter("Notizen.txt", true));

            userInput.setOnAction(new EnterHandler(userInput, output));
        } catch (IOException exception) {
            var alert = new Alert(AlertType.ERROR, exception.getMessage());
            alert.showAndWait();
        }
        stage.show();
    }

    @Override
    public void stop() throws IOException {
        if (this.output != null) {
            output.close();
        }
    }
}