Swing - 替换 Qt 信号/插槽 [英] Swing - replacement for Qt signal/slots

查看:60
本文介绍了Swing - 替换 Qt 信号/插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Qt GUI 中,使用信号和信号非常方便.插槽 - 它解耦事件传递.当我创建一些抛出信号的小部件时,我不必事先知道谁可以得到它,然后用 connect 指定连接.

In Qt GUIs it is very convenient use signals & slots - it decouple events passing. When I create some widget that throw signal, I don't have to know in advance who can get it, and later with connect I specify connections.

Java/Swing 中的并行是什么?你能指出关于这个问题的好资源吗?

What is parallel in Java/Swing? Can you point to good resources on this issue?

推荐答案

如果现有 EventListener 实现满足您的要求,您可以创建自己的自定义事件.每个 JComponent 包含 EventListenerList.您可以使用 EventListenerList API 以启用您的自定义 JComponent 子类来触发您的自定义事件.

If none of the existing EventListener implementations meet your requirements, you can create your own custom event. Every JComponent contains a field of type EventListenerList. You can use the approach outlined in the EventListenerList API to enable your custom JComponent subclass to fire your custom event.

关于信号/槽机制,Swing 有几种实现观察者模式的方法,在此处概述.

Regarding the signal/slot mechanism, Swing has several ways to implement the observer pattern, outlined here.

这篇关于Swing - 替换 Qt 信号/插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆