开发者

Fire action in JPanel subclass

I know how to use an ActionListener class to pick up an actionPerformed event - however, I've implemented my own JPanel object and som开发者_运维问答ething I can't work out is how I create an action and indicate it has been performed such that an external action listener can pick up on it. Specifically, I wish to intercept an action of an internal component, transform its getSelectedValue() and store this into a local variable available via a getter. I then want to indicate the change such that an external class can pick up on this and read the value and act upon it.

Any ideas? I imagine this is quite straightforward but I can't find what I'm looking for on Google.


See Component.dispatchEvent to dispatch event types that are already defined on your component. If you add new event types, this may require a little more work. See how AbstractButton ties into JComponent's listenerList when adding the ActionListener options.


You could use the observer pattern by extending Observable and making calls to the setChanged and notifyObservers methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜