Browse Source

Merge branch 'JSrollBar' into 'main'

J sroll bar

See merge request fdai7332/java-chat!6
remotes/origin/server
fdai7579 11 months ago
parent
commit
a2537d42e5
  1. 45
      src/main/java/ChatClient.java

45
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() {
public ChatClient(int port) {
super("Chat"); super("Chat");
address = JOptionPane.showInputDialog("bitte IP-Adresse"); address = JOptionPane.showInputDialog("bitte IP-Adresse");
if (null != address) { if (null != address) {
@ -33,6 +33,8 @@ 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);
@ -53,34 +55,39 @@ 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());
// while (true) {
// String message = fromServerReader.readLine();
// outputTextArea.append(message + "\n");
// outputScrollPane.getVerticalScrollBar().setValue(outputScrollPane.getVerticalScrollBar().getMaximum());
// }
// Solang fromServerReader nicht erstellt ist als Kommentar
} }
} catch (IOException e) {
JOptionPane.showMessageDialog(null, connectionFailedMessage);
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen.");
dispose(); dispose();
} finally {
if (null != connectionToServer) {
}
finally {
if (connectionToServer != null) {
try { try {
connectionToServer.close(); connectionToServer.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
if (null != fromServerReader) {
try {
fromServerReader.close();
} catch (IOException e) {
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
/* if (fromServerReader != null) {
if(null != toServerWriter) {
toServerWriter.close();
}
fromServerReader.close(); (warten auf ServerReader)
} */
/* if (toServerWriter != null) {
toServerWriter.close(); (warten auf ServerWriter)
} */
} }
} }

Loading…
Cancel
Save