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.

BtnController.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 netz.controller;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.util.logging.Logger;
  10. import netz.model.ChatModel;
  11. import netz.view2.ChatView;
  12. import ohmlogger.OhmLogger;
  13. /**
  14. *
  15. * @author chris
  16. */
  17. public class BtnController implements ActionListener
  18. {
  19. private ChatView view;
  20. private ChatModel model;
  21. private static Logger lg = OhmLogger.getLogger();
  22. /**
  23. *
  24. * @param view
  25. * @param model
  26. */
  27. public BtnController(ChatView view, ChatModel model)
  28. {
  29. this.view = view;
  30. this.model = model;
  31. }
  32. public void registerEvents()
  33. {
  34. view.getBtnSetClient().addActionListener(this);
  35. view.getBtnSetServer().addActionListener(this);
  36. }
  37. @Override
  38. public void actionPerformed(ActionEvent e)
  39. {
  40. if(e.getSource() == view.getBtnSetClient())
  41. {
  42. view.getLblType().setText("Client");
  43. try
  44. {
  45. model.startClient(36000, "127.0.0.1",new ChatController(view, model));
  46. }
  47. catch (Exception ex)
  48. {
  49. System.err.println(ex);
  50. ex.printStackTrace();
  51. }
  52. } else {
  53. view.getLblType().setText("Server");
  54. try
  55. {
  56. model.startServer(36000, new ChatController(view, model));
  57. }
  58. catch (Exception ex)
  59. {
  60. System.err.println(ex);
  61. ex.printStackTrace();
  62. }
  63. }
  64. }
  65. }