package GUIAnwendungen.Meine_GUI_Chat;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChatManager implements ActionListener {

    private ChatFenster sender;
    private ChatFenster receiver;

    ChatManager(ChatFenster sender, ChatFenster receiver) {
        this.sender = sender;
        this.receiver = receiver;
        sender.getChat().getSendeNachricht().addActionListener(this);
        receiver.getChat().getSendeNachricht().addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String nachricht = sender.getChat().getEingabeNachricht().getText();
        if (!nachricht.isEmpty()) {
            sender.sendeNachricht(nachricht);
            receiver.empfangeNachricht(sender.getUser().getName() + ": " + nachricht);
            sender.getChat().getEingabeNachricht().setText("");
        }
    }
}