From 3072cf2853cdc552f781ecfefb53ec787b588a4b Mon Sep 17 00:00:00 2001 From: Alena Bandarovich Date: Sat, 3 Feb 2024 19:51:03 +0100 Subject: [PATCH] add GUI window for chat --- src/main/java/ChatClient.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/ChatClient.java b/src/main/java/ChatClient.java index 3627c91..5c60638 100644 --- a/src/main/java/ChatClient.java +++ b/src/main/java/ChatClient.java @@ -2,12 +2,13 @@ import javax.swing.*; import java.io.IOException; import java.net.Socket; -public class ChatClient { +public class ChatClient extends JFrame { private String address; private int port; private Socket connectionToServer; - + public ChatClient(int port) { + super("Chat"); this.port = port; address = JOptionPane.showInputDialog("bitte IP-Adresse"); @@ -16,10 +17,18 @@ public class ChatClient { } } + private void initGui() { + setVisible(true); + setSize(800, 600); + setDefaultCloseOperation(EXIT_ON_CLOSE); + } private void receiveMessages() { try { - connectionToServer = new Socket(address, port); - } catch (IOException e) { + // Um GUI zu testen + // Kommentar in der Zeile 28 wird weggenohmen, wenn der Server erstellt wird. + // connectionToServer = new Socket(address, port); + initGui(); + } catch (Exception e) { JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); } }