0
嗨,大家好,我有一个问题,我搜索了一些东西,但没有找到有趣的东西。事件和处理程序,Java中的EventBus
我有两个线程在Java中,一个在后台另一个在前台(UI)。 当背景的线程改变gui变量的状态时,我想发送一个异步事件。存在事件,处理者,但所有这些员工都需要实施。
是否存在任何简短的方式来传递类似于EventBus的事件?
谢谢!
嗨,大家好,我有一个问题,我搜索了一些东西,但没有找到有趣的东西。事件和处理程序,Java中的EventBus
我有两个线程在Java中,一个在后台另一个在前台(UI)。 当背景的线程改变gui变量的状态时,我想发送一个异步事件。存在事件,处理者,但所有这些员工都需要实施。
是否存在任何简短的方式来传递类似于EventBus的事件?
谢谢!
您可以尝试Google Guava EventBus。
以下是从Guava EventBus Examples by Ram Satish
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");
}
}
一个简单的例子