|
|
@ -17,7 +17,7 @@ public class ChatClient extends JFrame implements KeyListener { |
|
|
|
private JTextField inputTextField; |
|
|
|
private JScrollPane outputScrollPane; |
|
|
|
|
|
|
|
public ChatClient(int port) { |
|
|
|
public ChatClient() { |
|
|
|
super("Chat"); |
|
|
|
address = JOptionPane.showInputDialog("bitte IP-Adresse"); |
|
|
|
if (null != address) { |
|
|
@ -33,8 +33,6 @@ public class ChatClient extends JFrame implements KeyListener { |
|
|
|
|
|
|
|
outputScrollPane = new JScrollPane(outputTextArea); |
|
|
|
|
|
|
|
outputScrollPane = new JScrollPane(outputTextArea); |
|
|
|
|
|
|
|
inputTextField = new JTextField(); |
|
|
|
inputTextField.setBorder(BorderFactory.createTitledBorder("Nachricht eingeben")); |
|
|
|
inputTextField.addKeyListener(this); |
|
|
@ -55,39 +53,34 @@ public class ChatClient extends JFrame implements KeyListener { |
|
|
|
|
|
|
|
initGui(); |
|
|
|
|
|
|
|
// while (true) { |
|
|
|
// String message = fromServerReader.readLine(); |
|
|
|
// outputTextArea.append(message + "\n"); |
|
|
|
// outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); |
|
|
|
// } |
|
|
|
// Solang fromServerReader nicht erstellt ist als Kommentar |
|
|
|
while (true) { |
|
|
|
String message = fromServerReader.readLine(); |
|
|
|
outputTextArea.append(message + "\n"); |
|
|
|
outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); |
|
|
|
} catch (IOException e) { |
|
|
|
JOptionPane.showMessageDialog(null, connectionFailedMessage); |
|
|
|
dispose(); |
|
|
|
} |
|
|
|
finally { |
|
|
|
if (connectionToServer != null) { |
|
|
|
} finally { |
|
|
|
if (null != connectionToServer) { |
|
|
|
try { |
|
|
|
connectionToServer.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (IOException e) { |
|
|
|
// TODO Auto-generated catch block |
|
|
|
if (null != fromServerReader) { |
|
|
|
try { |
|
|
|
fromServerReader.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
/* if (fromServerReader != null) { |
|
|
|
|
|
|
|
fromServerReader.close(); (warten auf ServerReader) |
|
|
|
} */ |
|
|
|
/* if (toServerWriter != null) { |
|
|
|
|
|
|
|
toServerWriter.close(); (warten auf ServerWriter) |
|
|
|
} */ |
|
|
|
if(null != toServerWriter) { |
|
|
|
toServerWriter.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|