gpt4 book ai didi

java - 事件和处理程序,Java 中的 EventBus

转载 作者:行者123 更新时间:2023-12-01 10:33:03 25 4
gpt4 key购买 nike

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

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

Android 中是否存在像 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");
}
}

关于java - 事件和处理程序,Java 中的 EventBus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34980710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com