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.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 controller;
  7. import controller.commands.CommandLoescheDaten;
  8. import controller.commands.CommandNeueDaten;
  9. import controller.commands.CommandOpen;
  10. import controller.commands.CommandSave;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import model.AdressverwaltungModel;
  14. import view.Adressverwaltung;
  15. /**
  16. *
  17. * @author nobody
  18. */
  19. public class CommandController implements ActionListener
  20. {
  21. private Adressverwaltung view;
  22. private AdressverwaltungModel model;
  23. private CommandInvoker invoker;
  24. public CommandController(Adressverwaltung view,AdressverwaltungModel model)
  25. {
  26. this.view = view;
  27. this.model = model;
  28. invoker = new CommandInvoker();
  29. }
  30. public void registerEvents()
  31. {
  32. view.getMnuioeffnen().addActionListener(this);
  33. view.getMnuispeichern().addActionListener(this);
  34. view.getMnuineueadresse().addActionListener(this);
  35. view.getMnuiloescheadresse().addActionListener(this);
  36. view.getBtnoeffnen().addActionListener(this);
  37. view.getBtnspeichern().addActionListener(this);
  38. view.getBtnneueadresse().addActionListener(this);
  39. view.getBtnloescheadresse().addActionListener(this);
  40. }
  41. public void registerCommands()
  42. {
  43. invoker.addCommand(view.getMnuioeffnen(), new CommandOpen(view, model));
  44. invoker.addCommand(view.getMnuispeichern(), new CommandSave(view,model));
  45. invoker.addCommand(view.getMnuineueadresse(),new CommandNeueDaten(view,model));
  46. invoker.addCommand(view.getMnuiloescheadresse(),new CommandLoescheDaten(view,model));
  47. }
  48. @Override
  49. public void actionPerformed(ActionEvent e)
  50. {
  51. Object key = e.getSource();
  52. invoker.executeCommand(key);
  53. }
  54. }