开发者

Swing - replacement for Qt signal/slots

开发者 https://www.devze.com 2023-03-10 04:17 出处:网络
In Qt GUIs it is very convenient use signals & slots - it decouple events passing. When I create some widget that throw signal, I don开发者_Go百科\'t have to know in advance who can get it, and la

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

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


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.

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


This Event Listener tutorial goes through the basics of handling events with listeners.

Connecting your slot for a signal is analogous to adding your EventListener to an event-producing object.

0

精彩评论

暂无评论...
验证码 换一张
取 消