Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are 3 different ways you may wish to set this up:</p> <ol> <li><code>Thrower</code> inside of <code>Catcher</code></li> <li><code>Catcher</code> inside of <code>Thrower</code></li> <li><code>Thrower</code> and <code>Catcher</code> inside of another class in this example <code>Test</code></li> </ol> <p><strong><a href="https://github.com/GlassGhost/EventTest#hexed" rel="nofollow">THE WORKING GITHUB EXAMPLE I AM CITING</a></strong> Defaults to Option 3, to try the others simply uncomment the "<code>Optional</code>" code block of the class you want to be main, and set that class as the <code>${Main-Class}</code> variable in the <code>build.xml</code> file:</p> <p><strong>4 Things needed on throwing side code:</strong></p> <pre><code>import java.util.*;//import of java.util.event //Declaration of the event's interface type, OR import of the interface, //OR declared somewhere else in the package interface ThrowListener { public void Catch(); } /*_____________________________________________________________*/class Thrower { //list of catchers &amp; corresponding function to add/remove them in the list List&lt;ThrowListener&gt; listeners = new ArrayList&lt;ThrowListener&gt;(); public void addThrowListener(ThrowListener toAdd){ listeners.add(toAdd); } //Set of functions that Throw Events. public void Throw(){ for (ThrowListener hl : listeners) hl.Catch(); System.out.println("Something thrown"); } ////Optional: 2 things to send events to a class that is a member of the current class . . . go to github link to see this code . . . } </code></pre> <hr> <p><strong>2 Things needed in a class file to receive events from a class</strong></p> <pre><code>/*_______________________________________________________________*/class Catcher implements ThrowListener {//implement added to class //Set of @Override functions that Catch Events @Override public void Catch() { System.out.println("I caught something!!"); } ////Optional: 2 things to receive events from a class that is a member of the current class . . . go to github link to see this code . . . } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload