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