Forums Register Login

Java Event handling

+Pie Number of slices to send: Send
Can someone point me to a sample involving non-component based event handling?
All the samples that i find are event handlers being tied to AWT components?
I just wish to write a simple server which calls back on registered listeners(clients),by programmatically raising an event from one of the clients.
Any help will be appreciated.
+Pie Number of slices to send: Send
Have you taken a look to the java.util.Observer and java.util.Observable?
+Pie Number of slices to send: Send
I'm not a fan of Observer and Observable in the library. Before I even found them I made my own pub-sub with an intermediary. The flow is described HERE. I make an interface with methods for the events, implement it once in the intermediary and again in each subscriber. Here's an example with two events:

The abstract Publisher has (dead simple) methods to subscribe and unsubscribe. Some may be offended that I have to copy-paste that little loop for every event. But the flexibility I have here is pretty cool. I can pass parameters and get return types. I could let all the listeners vote on what to do next or let one of them signal that it has consumed the event and stop looping. I can have multiple publishers for the same event. Publishers can come and go while the subscription persists. Good fun.
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 619 times.
Similar Threads
Send data to front end when back end update
how to soloving this problem?
finalization, serialization and paint.
Core Java Fundamentals or The Java Tutorial , which one is more suitable for me?
Custom Cell renderer... A solution?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:31:04.