0

大家好,我有一个问题,我用谷歌搜索了一些东西,但没有找到有趣的东西。

我在java中有两个线程,一个在后台,另一个在前台(UI)。当背景的线程改变 gui 变量的状态时,我想发送一个异步事件。存在事件、处理程序,但所有这些人员都需要实现。

是否存在任何更短的方法来传递像 Android 中的 EventBus 这样的事件?

谢谢!

4

1 回答 1

1

你可以试试Google Guava EventBus

以下是Ram Satish 的 Guava EventBus 示例中的一个简单示例

package com.javarticles.guava;

import com.google.common.eventbus.EventBus;

public class SimpleEventBusExample {
    public static void main(String[] args) {
        EventBus eventBus = new EventBus();
        eventBus.register(new SimpleListener());
        System.out.println("Post Simple EventBus Example");
        eventBus.post("Simple EventBus Example");
    }
}
于 2016-01-24T20:00:34.567 回答