We all know how the events are generated and how to response to those events. However all these events are in-build. For example ActionEvent is generated, when u click a button. Similarly, I want my own event should be generated when certain condition is satisfied...For example, LessBalanceEvent should be generated when a condition such as balance < 500 rupees is satisfied and I also having a doubt that how can I register my LessBalanceEvent to a object by using addBalanceListener() I would be thankful one and all, who can assit me in this. I would also thank you, if you gave sample program. Thank you in advance
There's nothing magical about generating or firing an event. If you had an Account object it might have something like this:
LowBalanceListener would be an interface you created to define the lowBalanceEvent() method. You'd also need add and remove listener methods and that kind of housekeeping stuff.
You can get a lot of this functionality from Observable in the standard Java API. Before I found Observable I wrote my own little event publisher which is much simpler and more flexible but requries more hand-written implementation. Let me know if that sounds interesting. But look into Observable and Observer first.
Let us know if that helps!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi