title: Listener for another thread
body: <p>I have an application that has a GUI and TCP server. The TCP server is running in a different thread and when it receives a certain packet, it should start playing a video file (from MediaPlayer object). The problem is that as a GUI component, the video may be displayed only if invoked from the main thread. I added a listener class to the main class:</p>
  
  <pre><code>Class RequestListener implements NBRequestListener{  /* NBRequestListener is the interface */
  public void onRequestArrived(String request) {
  processRequest(request); /* This method will run the video */
  }
  </code></pre>
  
  <p>I created a listener in the main thread and set it as a listener in the server:</p>
  
  <pre><code>RequestListener listener = new RequestListener();
  server.setRequestListener(listener);
  </code></pre>
  
  <p>The code in the server is:</p>
  
  <pre><code>public void setRequestListener(_listener) {
  listener = _listener; } /* listener is defined as RequestListener */
  </code></pre>
  
  <p>and the invocation of the event (in the server) is simply:</p>
  
  <pre><code>listener.onRequestArrived(input_from_client);
  </code></pre>
  
  <p>But the listener method is invoked in the server thread and not in the main thread and therefore I get exception: <code>java.lang.reflect.InvocationTargetException</code>.  Could you please help pointing the problem?</p>