diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 30b486c..8476ae0 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -16,8 +16,8 @@ public class ChatClient extends JFrame implements KeyListener { private JTextArea outputTextArea; private JTextField inputTextField; private JScrollPane outputScrollPane; - - public ChatClient() { + + public ChatClient(int port) { super("Chat"); address = JOptionPane.showInputDialog("bitte IP-Adresse"); if (null != address) { @@ -30,6 +30,8 @@ public class ChatClient extends JFrame implements KeyListener { outputTextArea = new JTextArea(); outputTextArea.setEditable(false); outputTextArea.setBorder(BorderFactory.createTitledBorder("Chat")); + + outputScrollPane = new JScrollPane(outputTextArea); outputScrollPane = new JScrollPane(outputTextArea); @@ -52,35 +54,40 @@ public class ChatClient extends JFrame implements KeyListener { toServerWriter = new PrintWriter(new OutputStreamWriter(connectionToServer.getOutputStream())); initGui(); - - while (true) { - String message = fromServerReader.readLine(); - outputTextArea.append(message + "\n"); - outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); - } - } catch (IOException e) { - JOptionPane.showMessageDialog(null, connectionFailedMessage); + + // while (true) { + // String message = fromServerReader.readLine(); + // outputTextArea.append(message + "\n"); + // outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); + // } + // Solang fromServerReader nicht erstellt ist als Kommentar + } + + + + catch (Exception e) { + JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); dispose(); - } finally { - if (null != connectionToServer) { - try { - connectionToServer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - if (null != fromServerReader) { - try { - fromServerReader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - if(null != toServerWriter) { - toServerWriter.close(); - } + } + finally { + if (connectionToServer != null) { + try { + connectionToServer.close(); + } + + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /* if (fromServerReader != null) { + + fromServerReader.close(); (warten auf ServerReader) + } */ + /* if (toServerWriter != null) { + + toServerWriter.close(); (warten auf ServerWriter) + } */ } }