From d91356f9ee7989633eb6344d887e3c5341370923 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:16:32 +0100 Subject: [PATCH] try_catch_SaveNote --- src/main/java/Notizbuch.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 1c1bd38..83510ee 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -50,7 +50,12 @@ public class Notizbuch extends JFrame implements ActionListener { } private void saveNote() { - + try (PrintWriter writer = new PrintWriter(new FileWriter("notizen.txt"))) { + writer.print(textArea.getText()); + JOptionPane.showMessageDialog(this, "Notiz erfolgreich gespeichert!"); + } catch (IOException e) { + JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Notiz: " + e.getMessage()); + } } private void loadNote() {