Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
jvx:reference [2020/06/24 15:41] cduncan [JVx Style] |
jvx:reference [2020/06/24 15:44] cduncan [Creating your own events] |
||
---|---|---|---|
Line 1853: | Line 1853: | ||
==== Lambdas ==== | ==== Lambdas ==== | ||
- | Yet there is more, we can of course attach [[https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html|lambdas]] to the events as listeners, too: | + | Yet there is more. We can, of course, attach [[https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html|lambdas]] to the events as listeners too: |
<code java> | <code java> | ||
Line 1870: | Line 1870: | ||
} | } | ||
</code> | </code> | ||
- | ==== Method references ==== | + | ==== Method References ==== |
- | And last but not least, thanks to the new capabilities of Java 1.8, we can also use [[https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html|method references]]: | + | Lastly, thanks to the new capabilities of Java 1.8, we can also use [[https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html|method references]]: |
<code java> | <code java> | ||
Line 1894: | Line 1894: | ||
} | } | ||
</code> | </code> | ||
- | ===== Parameters or no parameters? To throw or not to throw? ===== | + | ===== Parameters or No Parameters? To Throw or Not to Throw? ===== |
- | By default we actually support two different classes of listeners, the specified event/listener interface itself, and ''%%javax.rad.util.IRunnable%%''. Which means that you can also attach methods which do not have any parameters, like this: | + | By default we actually support two different classes of listeners, the specified event/listener interface itself and ''%%javax.rad.util.IRunnable%%''. This means you can also attach methods that do not have any parameters, like this: |
<code java> | <code java> | ||
Line 1924: | Line 1924: | ||
} | } | ||
</code> | </code> | ||
- | Additionally, all listeners and ''%%IRunnable%%'' itself do support to throw ''%%Throwable%%'', which is then handled inside the ''%%EventHandler%%''. So you are very flexible when it comes to what methods you can attach and use as listeners. | + | Additionally, all listeners and ''%%IRunnable%%'' itself support throwing ''%%Throwable%%'', which is then handled inside the ''%%EventHandler%%''. As you can see, you are very flexible when it comes to what methods you can attach and use as listeners. |
- | ===== Creating your own events ===== | + | ===== Creating Your Own Events ===== |
You can, of course, create your own ''%%EventHandler%%''s and listeners to create your own events. All you need are two classes, an extension of EventHandler and a listener interface. | You can, of course, create your own ''%%EventHandler%%''s and listeners to create your own events. All you need are two classes, an extension of EventHandler and a listener interface. |