From 118683356fd060847284a617f94fafae0baa1d46 Mon Sep 17 00:00:00 2001 From: Alena Bandarovich Date: Wed, 7 Feb 2024 21:05:37 +0100 Subject: [PATCH] Refactor: Create variable for connection failed message --- src/main/java/ChatClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index cd73618..30b486c 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -7,6 +7,7 @@ import java.net.Socket; public class ChatClient extends JFrame implements KeyListener { private String address; + private String connectionFailedMessage; private Socket connectionToServer; private BufferedReader fromServerReader; private PrintWriter toServerWriter; @@ -19,8 +20,8 @@ public class ChatClient extends JFrame implements KeyListener { public ChatClient() { super("Chat"); address = JOptionPane.showInputDialog("bitte IP-Adresse"); - if (null != address) { + connectionFailedMessage = "Verbindung zum Server " + (address.isEmpty() ? "" : ("\"" + address + "\"")) + " fehlgeschlagen."; receiveMessages(); } } @@ -58,7 +59,7 @@ public class ChatClient extends JFrame implements KeyListener { outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); } } catch (IOException e) { - JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); + JOptionPane.showMessageDialog(null, connectionFailedMessage); dispose(); } finally { if (null != connectionToServer) {