Browse Source

ChatClient-Fix

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

61
src/main/java/ChatClient.java

@ -17,7 +17,7 @@ public class ChatClient extends JFrame implements KeyListener {
private JTextField inputTextField; private JTextField inputTextField;
private JScrollPane outputScrollPane; private JScrollPane outputScrollPane;
public ChatClient(int port) {
public ChatClient() {
super("Chat"); super("Chat");
address = JOptionPane.showInputDialog("bitte IP-Adresse"); address = JOptionPane.showInputDialog("bitte IP-Adresse");
if (null != address) { if (null != address) {
@ -33,8 +33,6 @@ public class ChatClient extends JFrame implements KeyListener {
outputScrollPane = new JScrollPane(outputTextArea); outputScrollPane = new JScrollPane(outputTextArea);
outputScrollPane = new JScrollPane(outputTextArea);
inputTextField = new JTextField(); inputTextField = new JTextField();
inputTextField.setBorder(BorderFactory.createTitledBorder("Nachricht eingeben")); inputTextField.setBorder(BorderFactory.createTitledBorder("Nachricht eingeben"));
inputTextField.addKeyListener(this); inputTextField.addKeyListener(this);
@ -55,39 +53,34 @@ public class ChatClient extends JFrame implements KeyListener {
initGui(); 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 (IOException e) {
JOptionPane.showMessageDialog(null, connectionFailedMessage);
dispose();
} finally {
if (null != connectionToServer) {
try {
connectionToServer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != fromServerReader) {
try {
fromServerReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen.");
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)
} */
if(null != toServerWriter) {
toServerWriter.close();
}
} }
} }

Loading…
Cancel
Save