From bea54c3a9612e4484a59329cec906a40d541f5c1 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 14:36:45 +0100 Subject: [PATCH 01/11] JScrollPane variable erstellt --- src/main/java/ChatClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 8d0b776..1068810 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -13,7 +13,8 @@ public class ChatClient extends JFrame implements KeyListener { // GUI private JTextArea outputTextArea; private JTextField inputTextField; - + private JScrollPane outputScrollPane; + public ChatClient(int port) { super("Chat"); this.port = port; From 2e7f779477dab3bba64ac5930a858cd4b0d31484 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 20:04:41 +0100 Subject: [PATCH 02/11] ScrollPane mit Parameter --- src/main/java/ChatClient.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 1068810..95aa15f 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -29,6 +29,8 @@ public class ChatClient extends JFrame implements KeyListener { outputTextArea = new JTextArea(); outputTextArea.setEditable(false); outputTextArea.setBorder(BorderFactory.createTitledBorder("Chat")); + + outputScrollPane = new JScrollPane(outputTextArea); inputTextField = new JTextField(); inputTextField.setBorder(BorderFactory.createTitledBorder("Nachricht eingeben")); From bffeecad92f0e31a8d1c16f744b3383715f339a9 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 20:06:04 +0100 Subject: [PATCH 03/11] TextArea zu ScrollPane --- src/main/java/ChatClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 95aa15f..ae08a81 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -36,7 +36,7 @@ public class ChatClient extends JFrame implements KeyListener { inputTextField.setBorder(BorderFactory.createTitledBorder("Nachricht eingeben")); inputTextField.addKeyListener(this); - add(outputTextArea, BorderLayout.CENTER); + add(outputScrollPane, BorderLayout.CENTER); add(inputTextField, BorderLayout.SOUTH); setVisible(true); From b892c620237ae2a0149ba07ccb2a5c68482c6d1c Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 20:28:26 +0100 Subject: [PATCH 04/11] while schleife in receive Message (kommentar) --- src/main/java/ChatClient.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index ae08a81..5b967af 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -47,7 +47,17 @@ public class ChatClient extends JFrame implements KeyListener { try { connectionToServer = new Socket(address, port); initGui(); - } catch (Exception e) { + + // while (true) { + // String message = fromServerReader.readLine(); + // outputTextArea.append(message + "\n"); + // } + // Solang fromServerReader nicht erstellt ist als Kommentar + } + + + + catch (Exception e) { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); } } From 843d914032458705e1eba83f16023b0ccbf660f5 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 20:31:34 +0100 Subject: [PATCH 05/11] Scrolled automatisch runter (in receive Message) --- src/main/java/ChatClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 5b967af..dac4280 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -51,6 +51,7 @@ public class ChatClient extends JFrame implements KeyListener { // while (true) { // String message = fromServerReader.readLine(); // outputTextArea.append(message + "\n"); + // outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); // } // Solang fromServerReader nicht erstellt ist als Kommentar } From e16619ebb1f18ff41d2c34c6b3c8ebaf30f40163 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 20:37:05 +0100 Subject: [PATCH 06/11] Finally box, connectionToServer --- src/main/java/ChatClient.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index dac4280..7eee6a4 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -61,6 +61,15 @@ public class ChatClient extends JFrame implements KeyListener { catch (Exception e) { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); } + finally { + try { + connectionToServer.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } } @Override From a6c66bb82b3c5ed26639af6dd58ca93e4bb3fed7 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Wed, 7 Feb 2024 20:40:39 +0100 Subject: [PATCH 07/11] ServerReader und ServerWriter --- src/main/java/ChatClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 7eee6a4..2dfd152 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -68,7 +68,8 @@ public class ChatClient extends JFrame implements KeyListener { // TODO Auto-generated catch block e.printStackTrace(); } - + // fromServerReader.close(); (warten auf ServerReader) + // toServerWriter.close(); (warten auf ServerWriter) } } From 0cf1553f66c0222b25da92d02bbfd9c44399ff20 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Thu, 8 Feb 2024 15:02:11 +0100 Subject: [PATCH 08/11] if connectionToServer --- src/main/java/ChatClient.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 2dfd152..b038e1a 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -62,12 +62,16 @@ public class ChatClient extends JFrame implements KeyListener { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); } finally { - try { + if (connectionToServer != null) { + try { connectionToServer.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } + + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } // fromServerReader.close(); (warten auf ServerReader) // toServerWriter.close(); (warten auf ServerWriter) } From b3e23d1f3f692fed3e7be13664e590c1d3610e9c Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Thu, 8 Feb 2024 15:05:14 +0100 Subject: [PATCH 09/11] if fromServerReader --- src/main/java/ChatClient.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index b038e1a..ad481c8 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -72,8 +72,11 @@ public class ChatClient extends JFrame implements KeyListener { e.printStackTrace(); } } - // fromServerReader.close(); (warten auf ServerReader) - // toServerWriter.close(); (warten auf ServerWriter) + /* if (fromServerReader != null) { + + fromServerReader.close(); (warten auf ServerReader) + } */ + /* toServerWriter.close(); (warten auf ServerWriter) */ } } From 2528c64f654194dd1e06a23919ef5481647fe53f Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Thu, 8 Feb 2024 15:07:13 +0100 Subject: [PATCH 10/11] if toServerWriter --- src/main/java/ChatClient.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index ad481c8..d3d6300 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -75,8 +75,11 @@ public class ChatClient extends JFrame implements KeyListener { /* if (fromServerReader != null) { fromServerReader.close(); (warten auf ServerReader) - } */ - /* toServerWriter.close(); (warten auf ServerWriter) */ + } */ + /* if (toServerWriter != null) { + + toServerWriter.close(); (warten auf ServerWriter) + } */ } } From 4fc87b99aa572eb3b21d34321eaa282ae5445500 Mon Sep 17 00:00:00 2001 From: Marc Dimmerling Date: Fri, 9 Feb 2024 10:50:58 +0100 Subject: [PATCH 11/11] dispose --- src/main/java/ChatClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index d3d6300..b9b93b5 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -60,6 +60,7 @@ public class ChatClient extends JFrame implements KeyListener { catch (Exception e) { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); + dispose(); } finally { if (connectionToServer != null) {