开发者

Fire action in JPanel subclass

开发者 https://www.devze.com 2023-01-16 13:25 出处:网络
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

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

精彩评论

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

关注公众号