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.

ConnectController.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.net.InetAddress;
  10. import java.net.UnknownHostException;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import model.Transmitter;
  14. import view.ChatView;
  15. /**
  16. *
  17. * @author Apollo
  18. */
  19. public class ConnectController implements ActionListener
  20. {
  21. ChatView view;
  22. Transmitter model;
  23. int modus;
  24. public ConnectController(ChatView view,Transmitter model,int modus)
  25. {
  26. this.view = view;
  27. this.model = model;
  28. this.modus = modus;
  29. if(modus==0)
  30. {
  31. Thread chatter = new Thread(model);
  32. chatter.start();
  33. }
  34. try
  35. {
  36. String t;
  37. t = InetAddress.getLocalHost().getHostAddress();
  38. view.getTxteigeneIP().setText(t);
  39. }
  40. catch (UnknownHostException ex)
  41. {
  42. Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
  43. }
  44. }
  45. public void registerEvents()
  46. {
  47. view.getBtnverbinden().addActionListener(this);
  48. }
  49. @Override
  50. public void actionPerformed(ActionEvent arg0)
  51. {
  52. if(modus == 1)
  53. {
  54. model.setIP_ADRESSE(view.getTxtzielIP().getText());
  55. Thread chatter = new Thread(model);
  56. chatter.start();
  57. }
  58. else
  59. {
  60. view.getChatanzeige().setText("Server kann sich nicht verbinden");
  61. }
  62. }
  63. }