Does Java have native support for events, similar to that of C#?

前端 未结 9 2022
眼角桃花
眼角桃花 2020-12-19 03:19

I\'m a bit confused from what I\'ve heard Java doesn\'t do events.

But I know that it does GUI events.

Am I missing something? Does java have an event handli

9条回答
  •  我在风中等你
    2020-12-19 03:56

    I'm not knowledgeable about C#, but Java Beans that are not UI components can certainly notify Listeners about state changes using Events:

    http://java.sun.com/developer/onlineTraining/Beans/beans02/

    This has been part of the Java Beans spec since it first came out. Note the date on the tutorial: it's vintage 2000.

    The source and listener have to be running in the same JVM. You'd have to use a proxy to communicate with something running in another JVM, but it could be done.

    I Googled for the C# events tutorial and found this. Java's registering of listeners and firing of property changed events was reminiscent of what I saw when I skimmed the C# tutorial. Did I miss something important? (I'll admit that I didn't read deeply - no time right now.)

提交回复
热议问题