From 2ab9d3378fd4084d30fb9c89e0642bc30d1c4303 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:11:19 +0100 Subject: [PATCH 01/26] ChatClient Fix --- src/main/java/ChatClient.java | 67 ++++++++++++++++------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 8476ae0..30b486c 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -16,8 +16,8 @@ public class ChatClient extends JFrame implements KeyListener { private JTextArea outputTextArea; private JTextField inputTextField; private JScrollPane outputScrollPane; - - public ChatClient(int port) { + + public ChatClient() { super("Chat"); address = JOptionPane.showInputDialog("bitte IP-Adresse"); if (null != address) { @@ -30,8 +30,6 @@ public class ChatClient extends JFrame implements KeyListener { outputTextArea = new JTextArea(); outputTextArea.setEditable(false); outputTextArea.setBorder(BorderFactory.createTitledBorder("Chat")); - - outputScrollPane = new JScrollPane(outputTextArea); outputScrollPane = new JScrollPane(outputTextArea); @@ -54,40 +52,35 @@ public class ChatClient extends JFrame implements KeyListener { toServerWriter = new PrintWriter(new OutputStreamWriter(connectionToServer.getOutputStream())); initGui(); - - // while (true) { - // String message = fromServerReader.readLine(); - // outputTextArea.append(message + "\n"); - // outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); - // } - // Solang fromServerReader nicht erstellt ist als Kommentar - } - - - - catch (Exception e) { - JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); + + while (true) { + String message = fromServerReader.readLine(); + outputTextArea.append(message + "\n"); + outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); + } + } catch (IOException e) { + JOptionPane.showMessageDialog(null, connectionFailedMessage); dispose(); - } - finally { - if (connectionToServer != null) { - try { - connectionToServer.close(); - } - - catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - /* if (fromServerReader != null) { - - fromServerReader.close(); (warten auf ServerReader) - } */ - /* if (toServerWriter != null) { - - toServerWriter.close(); (warten auf ServerWriter) - } */ + } finally { + if (null != connectionToServer) { + try { + connectionToServer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + if (null != fromServerReader) { + try { + fromServerReader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + if(null != toServerWriter) { + toServerWriter.close(); + } } } From 8e30d9205dbea3284e7dd25fa4aa6c9b15842e1b Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:46:50 +0100 Subject: [PATCH 02/26] Notizbuch --- src/main/java/Notizbuch.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/Notizbuch.java diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java new file mode 100644 index 0000000..5b1d8a1 --- /dev/null +++ b/src/main/java/Notizbuch.java @@ -0,0 +1,17 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; + +public class Notizbuch extends JFrame implements ActionListener { + + public Notizbuch() { + + } + + @Override + public void actionPerformed(ActionEvent e) { + + + } +} \ No newline at end of file From 24eedd85a09412cc77918a26b31e9be3180bab2d Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:49:37 +0100 Subject: [PATCH 03/26] textArea --- src/main/java/Notizbuch.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 5b1d8a1..6edc3fe 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -1,10 +1,16 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; import javax.swing.JFrame; + public class Notizbuch extends JFrame implements ActionListener { + private JTextArea textArea; + public Notizbuch() { } From b58199854dcaec9eb51b3a91b33e35227b4b93f4 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:50:42 +0100 Subject: [PATCH 04/26] Button --- src/main/java/Notizbuch.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 6edc3fe..8662e18 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -6,10 +6,13 @@ import java.awt.event.*; import java.io.*; import javax.swing.JFrame; +import Test_Package.JButton; + public class Notizbuch extends JFrame implements ActionListener { private JTextArea textArea; + private JButton saveButton; public Notizbuch() { From a66e4a0ba12bbd40ceb984e95d11343a74603aa0 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:53:52 +0100 Subject: [PATCH 05/26] LoadButton --- src/main/java/Notizbuch.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 8662e18..4cf8fb1 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -6,14 +6,16 @@ import java.awt.event.*; import java.io.*; import javax.swing.JFrame; -import Test_Package.JButton; + + public class Notizbuch extends JFrame implements ActionListener { private JTextArea textArea; private JButton saveButton; - + private JButton loadButton; + public Notizbuch() { } From e2ee156dc7b28567b566f734c38733998e494d9d Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:55:26 +0100 Subject: [PATCH 06/26] setTitle --- src/main/java/Notizbuch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 4cf8fb1..b76a46e 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -17,7 +17,7 @@ public class Notizbuch extends JFrame implements ActionListener { private JButton loadButton; public Notizbuch() { - + setTitle("Notizbuch"); } @Override From 0b419079786a838c4a61a5cf9cdc2d5d980974d4 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:56:28 +0100 Subject: [PATCH 07/26] setSize --- src/main/java/Notizbuch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index b76a46e..25c312b 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -18,6 +18,7 @@ public class Notizbuch extends JFrame implements ActionListener { public Notizbuch() { setTitle("Notizbuch"); + setSize(400, 300); } @Override From 0c32ce33848d4d328fae24db90c2d9708563e803 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:57:25 +0100 Subject: [PATCH 08/26] Exit_on_close --- src/main/java/Notizbuch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 25c312b..23371dc 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -19,6 +19,7 @@ public class Notizbuch extends JFrame implements ActionListener { public Notizbuch() { setTitle("Notizbuch"); setSize(400, 300); + setDefaultCloseOperation(EXIT_ON_CLOSE); } @Override From 804d5bca2f117f42ceb49b8d84a910b8b1d6f0a9 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 16:59:13 +0100 Subject: [PATCH 09/26] BorderLayout --- src/main/java/Notizbuch.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 23371dc..f3fbf9b 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -6,6 +6,8 @@ import java.awt.event.*; import java.io.*; import javax.swing.JFrame; +import Test_Package.BorderLayout; + @@ -20,6 +22,7 @@ public class Notizbuch extends JFrame implements ActionListener { setTitle("Notizbuch"); setSize(400, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); + setLayout(new BorderLayout()); } @Override From 4824960065fd8b536952405bce0de156c7dd4d6d Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:00:25 +0100 Subject: [PATCH 10/26] new_textArea --- src/main/java/Notizbuch.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index f3fbf9b..73ca6e0 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -7,6 +7,7 @@ import java.io.*; import javax.swing.JFrame; import Test_Package.BorderLayout; +import Test_Package.JTextArea; @@ -23,6 +24,8 @@ public class Notizbuch extends JFrame implements ActionListener { setSize(400, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new BorderLayout()); + + textArea = new JTextArea(); } @Override From 503549677f11a304b19b5e0a6ca2baf4e6f5f625 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:01:13 +0100 Subject: [PATCH 11/26] new_ScrollPane --- src/main/java/Notizbuch.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 73ca6e0..fe05dcd 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -7,6 +7,7 @@ import java.io.*; import javax.swing.JFrame; import Test_Package.BorderLayout; +import Test_Package.JScrollPane; import Test_Package.JTextArea; @@ -26,6 +27,7 @@ public class Notizbuch extends JFrame implements ActionListener { setLayout(new BorderLayout()); textArea = new JTextArea(); + add(new JScrollPane(textArea), BorderLayout.CENTER); } @Override From 610f5471e029862f4b8236d8e545d135a09ef7f9 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:01:53 +0100 Subject: [PATCH 12/26] new_JButton --- src/main/java/Notizbuch.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index fe05dcd..531ec00 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -7,6 +7,7 @@ import java.io.*; import javax.swing.JFrame; import Test_Package.BorderLayout; +import Test_Package.JButton; import Test_Package.JScrollPane; import Test_Package.JTextArea; @@ -28,6 +29,8 @@ public class Notizbuch extends JFrame implements ActionListener { textArea = new JTextArea(); add(new JScrollPane(textArea), BorderLayout.CENTER); + + saveButton = new JButton("Speichern"); } @Override From ec2987e3cd627f9f5e0f8fa708226fd8150dc890 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:02:40 +0100 Subject: [PATCH 13/26] addActionSaveButton --- src/main/java/Notizbuch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 531ec00..6320e42 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -31,6 +31,7 @@ public class Notizbuch extends JFrame implements ActionListener { add(new JScrollPane(textArea), BorderLayout.CENTER); saveButton = new JButton("Speichern"); + saveButton.addActionListener(this); } @Override From f520fbbb38f77d64826241a14ac04f4f79831b3a Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:03:26 +0100 Subject: [PATCH 14/26] NewJButtonLoad --- src/main/java/Notizbuch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 6320e42..38e6307 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -32,6 +32,7 @@ public class Notizbuch extends JFrame implements ActionListener { saveButton = new JButton("Speichern"); saveButton.addActionListener(this); + loadButton = new JButton("Laden"); } @Override From 6d0343b2986c50d4e66c0c175a8a51478556d5ec Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:05:29 +0100 Subject: [PATCH 15/26] addActionLoad --- src/main/java/Notizbuch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 38e6307..396af41 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -33,6 +33,7 @@ public class Notizbuch extends JFrame implements ActionListener { saveButton = new JButton("Speichern"); saveButton.addActionListener(this); loadButton = new JButton("Laden"); + loadButton.addActionListener(this); } @Override From 7a0738cbefe682e717b31d7010bee9e5635b4755 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:06:34 +0100 Subject: [PATCH 16/26] buttonPanel --- src/main/java/Notizbuch.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 396af41..40b1c33 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -8,6 +8,7 @@ import javax.swing.JFrame; import Test_Package.BorderLayout; import Test_Package.JButton; +import Test_Package.JPanel; import Test_Package.JScrollPane; import Test_Package.JTextArea; @@ -34,6 +35,8 @@ public class Notizbuch extends JFrame implements ActionListener { saveButton.addActionListener(this); loadButton = new JButton("Laden"); loadButton.addActionListener(this); + + JPanel buttonPanel = new JPanel(); } @Override From 855a38d67439c42f2368ca28b0b74204f919d209 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:07:13 +0100 Subject: [PATCH 17/26] addSave&Load --- src/main/java/Notizbuch.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 40b1c33..1a0ce01 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -37,6 +37,8 @@ public class Notizbuch extends JFrame implements ActionListener { loadButton.addActionListener(this); JPanel buttonPanel = new JPanel(); + buttonPanel.add(saveButton); + buttonPanel.add(loadButton); } @Override From 4255c6779406e109c065b93e4c85665d8cd43d5f Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:08:32 +0100 Subject: [PATCH 18/26] BorderLayoutbutton --- src/main/java/Notizbuch.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 1a0ce01..b29b872 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -39,6 +39,8 @@ public class Notizbuch extends JFrame implements ActionListener { JPanel buttonPanel = new JPanel(); buttonPanel.add(saveButton); buttonPanel.add(loadButton); + + add(buttonPanel, BorderLayout.SOUTH); } @Override From 5913429e6c66c698cdfbe3bec33f694f9e3f8229 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:09:54 +0100 Subject: [PATCH 19/26] actionperf_if --- src/main/java/Notizbuch.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index b29b872..180a701 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -45,7 +45,9 @@ public class Notizbuch extends JFrame implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - + if (e.getSource() == saveButton) { + + } } } \ No newline at end of file From 934b469534b3f072c15ec2c004d074bd2d899505 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:13:27 +0100 Subject: [PATCH 20/26] LoadNote_ --- src/main/java/Notizbuch.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 180a701..1c1bd38 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -6,11 +6,7 @@ import java.awt.event.*; import java.io.*; import javax.swing.JFrame; -import Test_Package.BorderLayout; -import Test_Package.JButton; -import Test_Package.JPanel; -import Test_Package.JScrollPane; -import Test_Package.JTextArea; + @@ -46,8 +42,17 @@ public class Notizbuch extends JFrame implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == saveButton) { - + saveNote(); + } else if (e.getSource() == loadButton) { + loadNote(); } } + + private void saveNote() { + + } + private void loadNote() { + + } } \ No newline at end of file From d91356f9ee7989633eb6344d887e3c5341370923 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:16:32 +0100 Subject: [PATCH 21/26] 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() { From e0e12ac0f1bd755cd4b56b49b2b14a9f5c59914f Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:21:20 +0100 Subject: [PATCH 22/26] void_LoadNote --- src/main/java/Notizbuch.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 83510ee..8c467d2 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -58,6 +58,15 @@ public class Notizbuch extends JFrame implements ActionListener { } } private void loadNote() { - + try (BufferedReader reader = new BufferedReader(new FileReader("notizen.txt"))) { + StringBuilder noteText = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + + } + + } catch (IOException e) { + + } + } } -} \ No newline at end of file From a7d9bfe2566acd95b57616fb3445e4cbe4cd9760 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:21:55 +0100 Subject: [PATCH 23/26] NoteTextappend --- src/main/java/Notizbuch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 8c467d2..69f012f 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -62,7 +62,7 @@ public class Notizbuch extends JFrame implements ActionListener { StringBuilder noteText = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { - + noteText.append(line).append("\n"); } } catch (IOException e) { From 344f0ff0cd298fe1c75daec219eeffaa3c2c42e0 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:22:32 +0100 Subject: [PATCH 24/26] noteText.toString --- src/main/java/Notizbuch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 69f012f..15e9a09 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -64,7 +64,7 @@ public class Notizbuch extends JFrame implements ActionListener { while ((line = reader.readLine()) != null) { noteText.append(line).append("\n"); } - + textArea.setText(noteText.toString()); } catch (IOException e) { } From e4bee5bb122ed3fa23b944d50aff03e68888d3d7 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:23:01 +0100 Subject: [PATCH 25/26] Fehlermeldung --- src/main/java/Notizbuch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 15e9a09..18ef67c 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -66,7 +66,7 @@ public class Notizbuch extends JFrame implements ActionListener { } textArea.setText(noteText.toString()); } catch (IOException e) { - + JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage()); } } } From ad1a16fe26e1ea83e0fc07fd341192537898b9a2 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 17:23:33 +0100 Subject: [PATCH 26/26] Zeilensortierung --- src/main/java/Notizbuch.java | 59 +++++++++++++++++------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/main/java/Notizbuch.java b/src/main/java/Notizbuch.java index 18ef67c..caffb68 100644 --- a/src/main/java/Notizbuch.java +++ b/src/main/java/Notizbuch.java @@ -6,67 +6,62 @@ import java.awt.event.*; import java.io.*; import javax.swing.JFrame; - - - - - - public class Notizbuch extends JFrame implements ActionListener { private JTextArea textArea; private JButton saveButton; private JButton loadButton; - + public Notizbuch() { setTitle("Notizbuch"); setSize(400, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new BorderLayout()); - + textArea = new JTextArea(); add(new JScrollPane(textArea), BorderLayout.CENTER); - + saveButton = new JButton("Speichern"); saveButton.addActionListener(this); loadButton = new JButton("Laden"); loadButton.addActionListener(this); - + JPanel buttonPanel = new JPanel(); buttonPanel.add(saveButton); - buttonPanel.add(loadButton); - - add(buttonPanel, BorderLayout.SOUTH); + buttonPanel.add(loadButton); + + add(buttonPanel, BorderLayout.SOUTH); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == saveButton) { - saveNote(); - } else if (e.getSource() == loadButton) { - loadNote(); - } - + saveNote(); + } else if (e.getSource() == loadButton) { + loadNote(); + } + } - + 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()); - } + 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() { try (BufferedReader reader = new BufferedReader(new FileReader("notizen.txt"))) { StringBuilder noteText = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - noteText.append(line).append("\n"); - } - textArea.setText(noteText.toString()); - } catch (IOException e) { - JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage()); - } + String line; + while ((line = reader.readLine()) != null) { + noteText.append(line).append("\n"); + } + textArea.setText(noteText.toString()); + } catch (IOException e) { + JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage()); } } +}