Browse Source

Refactor: Create variable for connection failed message

remotes/origin/feature/client/exchange-messages-between-client-server
Alena Bandarovich 11 months ago
parent
commit
118683356f
  1. 5
      src/main/java/ChatClient.java

5
src/main/java/ChatClient.java

@ -7,6 +7,7 @@ import java.net.Socket;
public class ChatClient extends JFrame implements KeyListener { public class ChatClient extends JFrame implements KeyListener {
private String address; private String address;
private String connectionFailedMessage;
private Socket connectionToServer; private Socket connectionToServer;
private BufferedReader fromServerReader; private BufferedReader fromServerReader;
private PrintWriter toServerWriter; private PrintWriter toServerWriter;
@ -19,8 +20,8 @@ public class ChatClient extends JFrame implements KeyListener {
public ChatClient() { public ChatClient() {
super("Chat"); super("Chat");
address = JOptionPane.showInputDialog("bitte IP-Adresse"); address = JOptionPane.showInputDialog("bitte IP-Adresse");
if (null != address) { if (null != address) {
connectionFailedMessage = "Verbindung zum Server " + (address.isEmpty() ? "" : ("\"" + address + "\"")) + " fehlgeschlagen.";
receiveMessages(); receiveMessages();
} }
} }
@ -58,7 +59,7 @@ public class ChatClient extends JFrame implements KeyListener {
outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum());
} }
} catch (IOException e) { } catch (IOException e) {
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen.");
JOptionPane.showMessageDialog(null, connectionFailedMessage);
dispose(); dispose();
} finally { } finally {
if (null != connectionToServer) { if (null != connectionToServer) {

Loading…
Cancel
Save