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.

Controller.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package kontakte.controller ;
  7. import java.awt.Component;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import kontakte.model.Model;
  11. import kontakte.view.View;
  12. /**
  13. *
  14. * @author nobody
  15. */
  16. public class Controller implements ActionListener
  17. {
  18. private View view;
  19. private Model model;
  20. private CommandInvoker invoker;
  21. public Controller(View view, Model model)
  22. {
  23. this.view = view;
  24. this.model = model;
  25. invoker = new CommandInvoker();
  26. }
  27. public void registerEvents()
  28. {
  29. view.getBtnOpen().addActionListener(this);
  30. view.getMenuOpen().addActionListener(this);
  31. }
  32. public void registerCommands()
  33. {
  34. CommandOpen cmdOpen = new CommandOpen(view, model);
  35. invoker.addCommand(view.getBtnOpen(), cmdOpen);
  36. invoker.addCommand(view.getMenuOpen(), cmdOpen);
  37. }
  38. @Override
  39. public void actionPerformed(ActionEvent e)
  40. {
  41. Component key = (Component)e.getSource();
  42. invoker.executeCommand(key);
  43. }
  44. }