I know how to use an ActionListener class to pick up an actionPerformed event – however, I’ve implemented my own JPanel object and something 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.dispatchEventto dispatch event types that are already defined on your component. If you add new event types, this may require a little more work. See howAbstractButtonties intoJComponent‘slistenerListwhen adding theActionListeneroptions.