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 {
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) {

Loading…
Cancel
Save