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.

CommandConnect.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 chatProg.controller;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.io.IOException;
  10. import java.util.logging.Logger;
  11. import chatProg.logger.OhmLogger;
  12. import chatProg.model.ChatModel;
  13. import chatProg.view.ChatView;
  14. /**
  15. *
  16. * @author hd, chris
  17. */
  18. public class CommandConnect implements ActionListener
  19. {
  20. private static Logger lg = OhmLogger.getLogger();
  21. ChatView view;
  22. ChatModel model;
  23. private static final int PORT = 35000;
  24. private static final String IP_ADRESSE = "127.0.0.1";
  25. public CommandConnect(ChatView view, ChatModel transmitter)
  26. {
  27. this.view = view;
  28. this.model = transmitter;
  29. }
  30. public void registerEvents(){
  31. view.getBtnSetServer().addActionListener(this);
  32. view.getBtnSetClient().addActionListener(this);
  33. }
  34. @Override
  35. public void actionPerformed(ActionEvent e) {
  36. Object src = e.getSource();
  37. // connect to server
  38. if(src == view.getBtnSetServer()){
  39. synchronized (this){
  40. try {
  41. view.getLblType().setText("Server");
  42. model.setServer(PORT);
  43. } catch (IOException ex) {
  44. lg.severe(ex.toString());
  45. }
  46. }
  47. }
  48. // connect to vlient
  49. if(src == view.getBtnSetClient()){
  50. synchronized (this){
  51. try {
  52. view.getLblType().setText("Client");
  53. model.setClient(PORT, IP_ADRESSE);
  54. } catch (IOException ex) {
  55. lg.severe(ex.toString());
  56. }
  57. }
  58. }
  59. }
  60. }