title: How to implement callbacks in Java
body: <p>I have a class called CommunicationManager which is responsible for communication with server.</p>
  
  <p>It includes methods <code>login()</code> and <code>onLoginResponse()</code>. In case of user login the method <code>login()</code> has to be called and when the server responds the method <code>onLoginResponse()</code> is executed.</p>
  
  <p>What I want to do is to bind actions with user interface. In the GUI class I created an instance of CommunicationManager called <code>mCommunicationManager</code>. From GUI class the <code>login()</code> method is simply called by the line</p>
  
  <pre><code>mCommunicationManager.login();
  </code></pre>
  
  <p>What I don't know how to do is binding the method from GUI class to <code>onLoginResponse()</code>. For example if the GUI class includes the method <code>notifyUser()</code> which displays the message received from theserver.</p>
  
  <p>I would really appreciate if anyone could show how to bind methods in order to execute the method from GUI class (ex. <code>GUI.notifyUser()</code>) when the instance of the class <code>mCommunicationManager</code> receives the message from the server and the method <code>CommunicationManager.onLoginResponse()</code> is executed.</p>
  
  <p>Thanks!</p>