• Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic Questions regarding JButton

 
karl narkar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakkarn,

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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!