• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Basic Questions regarding JButton  RSS feed

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?
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!