Event Listeners in Java

后端 未结 5 550
陌清茗
陌清茗 2021-02-06 03:44

I\'ve been working with event listeners in AS3, but seems like there is none in java (except for graphics components). It\'s surprising.

The question is, how could i imp

5条回答
  •  情歌与酒
    2021-02-06 04:05

    First of all you need some source of events, so you can attache listener to it. If you need custom listener then you need also implement the custom source.

    In Java you can find existing sources and listener interfaces. As you mentioned GUI is usually based on events. If you are into 3D then rendering engines deliver appropriate API (eg. collision detection), file system hooks, properties change listeners (Android).

    It depends what are your needs. For most usages there should be already a library that delivers you appropriate API.

    While implementing your own solution then for application wide event handling the Event Bus might be a good choice. My preferred implementation is in Guava library: http://code.google.com/p/guava-libraries/wiki/EventBusExplained

提交回复
热议问题