You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandController.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3. * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
  4. */
  5. package ChatProgramm.controller;
  6. import ChatProgramm.controller.commands.CommandConnect;
  7. import ChatProgramm.controller.commands.CommandInvoker;
  8. import ChatProgramm.controller.commands.CommandSend;
  9. import ChatProgramm.view.ChatView;
  10. import java.awt.Component;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. /**
  14. *
  15. * @author ahren
  16. */
  17. public class CommandController implements ActionListener{
  18. private ChatView view;
  19. private CommandInvoker invoker;
  20. public CommandController(ChatView view){
  21. this.view = view;
  22. this.invoker = new CommandInvoker();
  23. }
  24. public void registerEvents(){
  25. view.getBtnConnect().addActionListener(this);
  26. view.getTfNachricht().addActionListener(this);
  27. }
  28. public void registerCommands(){
  29. CommandSend commandSend = new CommandSend(view);
  30. invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
  31. invoker.addCommand(view.getTfNachricht(), commandSend);
  32. }
  33. /**
  34. * Ausführen des jeweiligen Kommandos
  35. * @param e Referenz auf das Event
  36. */
  37. @Override
  38. public void actionPerformed(ActionEvent e) {
  39. Component key = (Component)e.getSource();
  40. invoker.executeCommand(key);
  41. // if(key == view.getBtnOpen()|| key==view.getMiOpen())
  42. // invoker.deleteStack();
  43. // }
  44. }
  45. }