Browse Source

ChatClient-Fix

remotes/origin/server
Marc Dimmerling 11 months ago
parent
commit
02c45605a4
  1. 67
      src/main/java/ChatClient.java

67
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(int port) {
public ChatClient() {
super("Chat");
address = JOptionPane.showInputDialog("bitte IP-Adresse");
if (null != address) {
@ -30,8 +30,6 @@ 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);
@ -54,40 +52,35 @@ 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());
// }
// Solang fromServerReader nicht erstellt ist als Kommentar
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen.");
while (true) {
String message = fromServerReader.readLine();
outputTextArea.append(message + "\n");
outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum());
}
} catch (IOException e) {
JOptionPane.showMessageDialog(null, connectionFailedMessage);
dispose();
}
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)
} */
} 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();
}
}
}

Loading…
Cancel
Save