title: How do I programmatically dispatch an event to get captured by another object in Java?
body: <p>When it comes to events, I definitely come from an ActionScript background. I am currently working on a project using Swing in which I need to dispatch an event from one object and capture the event in the parent, and I have no idea how to do it.</p>
  
  <p>In ActionScript3, you can dispatch an event with a dispatchEvent call. For example, let's say I wanted to programmatically dispatch a mouseClick event (even though the mouse was not clicked) so that some other listener will activate. I can do that by using</p>
  
  <pre><code>dispatchEvent(MouseEvent.Click);
  </code></pre>
  
  <p>Once that gets called, the event will bubble up through it's parent objects until it hits the top, and event listeners can capture it on the way. (Technically it bubbles down and back up, but that's outside the scope of the question, I believe). So if I want to listen for that mouseClick event in the parent object, I would just add a listener like so:</p>
  
  <pre><code>parent.addEventListener(MouseEvent.Click, Function);
  </code></pre>
  
  <p>Which would capture that mouseClick and perform the Function.</p>
  
  <p>That's how it works in ActionScript3. I'm trying to do something similar in Java, and there appears to be some big theory changes in how Java events work. How would I do the same thing in java? Specifically, how to I programmatically dispatch an event and capture that event in a parent object?</p>
  
  <p>I have done my own research on the subject, and it has merely confused me further. I have looked at:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/4753004/how-do-i-programatically-send-actionevent-to-jbutton">How do I programatically send ActionEvent to JButton?</a></li>
  <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html" rel="nofollow noreferrer">Concurrency in Swing - The Event Dispatch Thread</a>.</li>
  <li><a href="http://www.javaworld.com/article/2077351/java-se/events-and-listeners.html" rel="nofollow noreferrer">Events and listeners - How do you create a custom event?</a></li>
  </ul>