• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating User-Defined Events  RSS feed

 
GangaGang Reddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!