Browse Source

add GUI window for chat

remotes/origin/feature/client/exchange-messages-between-client-server
Alena Bandarovich 11 months ago
parent
commit
3072cf2853
  1. 17
      src/main/java/ChatClient.java

17
src/main/java/ChatClient.java

@ -2,12 +2,13 @@ import javax.swing.*;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
public class ChatClient {
public class ChatClient extends JFrame {
private String address; private String address;
private int port; private int port;
private Socket connectionToServer; private Socket connectionToServer;
public ChatClient(int port) { public ChatClient(int port) {
super("Chat");
this.port = port; this.port = port;
address = JOptionPane.showInputDialog("bitte IP-Adresse"); 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() { private void receiveMessages() {
try { 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."); JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen.");
} }
} }

Loading…
Cancel
Save