/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package ChatProgramm.controller; import ChatProgramm.controller.commands.CommandConnect; import ChatProgramm.controller.commands.CommandInvoker; import ChatProgramm.controller.commands.CommandSend; import ChatProgramm.model.GrafikModel; import ChatProgramm.view.ChatView; import ChatProgramm.view.GrafikView; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * * @author ahren */ public class CommandController implements ActionListener{ private ChatView view; private GrafikModel model; private GrafikView gView; private CommandInvoker invoker; private GrafikController controller; public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){ this.view = view; this.model = model; this.gView = gView; this.invoker = new CommandInvoker(); this.controller = controller; } public void registerEvents(){ view.getBtnConnect().addActionListener(this); //ToDo: muss auf gFrame referenzieren //view.getTfNachricht().addActionListener(this); } public void registerCommands(){ CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model); invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView)); this.controller.setCommand(commandSend); } /** * Ausführen des jeweiligen Kommandos * @param e Referenz auf das Event */ @Override public void actionPerformed(ActionEvent e) { Component key = (Component)e.getSource(); invoker.executeCommand(key); } }