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.

GrafikController.java 1.4KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.CommandSend;
  7. import java.awt.Point;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseMotionListener;
  11. import ChatProgramm.model.GrafikModel;
  12. import ChatProgramm.view.GrafikView;
  13. /**
  14. *
  15. * @author le
  16. */
  17. public class GrafikController extends MouseAdapter implements MouseMotionListener
  18. {
  19. private GrafikView view;
  20. private GrafikModel model;
  21. private CommandSend commandSend;
  22. public GrafikController(GrafikView view, GrafikModel model)
  23. {
  24. this.view = view;
  25. this.model = model;
  26. commandSend = null;
  27. }
  28. void setCommand(CommandSend command){
  29. this.commandSend = command;
  30. }
  31. public void registerEvents()
  32. {
  33. view.addMouseMotionListener(this);
  34. view.addMouseListener(this);
  35. }
  36. @Override
  37. public void mouseDragged(MouseEvent evt)
  38. {
  39. Point p = evt.getPoint();
  40. model.addPoint(p);
  41. view.drawPoint();
  42. }
  43. @Override
  44. public void mouseMoved(MouseEvent e)
  45. {
  46. }
  47. @Override
  48. public void mouseReleased(MouseEvent evt)
  49. {
  50. model.endShape();
  51. if(commandSend != null){
  52. commandSend.execute();
  53. }
  54. }
  55. }