As I understand the Swing architecture: 1) ActionListeners can be registered using JButton.addActionListener 2) Implicitly, the JButton has registered with the DefaultButtonModel as an Action Listener
Now when the user clicks the button 1) The DefaultButtonModel state will change, this causes an event to be queued on the EventQueue. The main thread is then relinquished 2) In the Event dispatcher thread, the JButton receives the event.
Now my question is:
Does the JButton in turn notify the listeners SYNCHRONOUSLY? or does it notify them by placing events again on the event queue?
The JButton notifies the listeners SYNCHRONOUSLY. If you throw a runtime exception in the actionPerformed() of one of the listeners, none of the other listeners which have not been invoked yet will be invoked.
Just remember that the current thread that invokes the actionPerformed() method WILL be the event dispatcher thread, so you are safe to invoke GUI methods from the actionPerformed() method. But, be aware that if your actionPerformed() method takes a while, your GUI will appear to be frozen.
SJCP, SCBCD, SJCD, SCDJWS, SCEA (Part I)
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
how do I do my own kindle-like thing - without amazon