• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what happens when an action occurs, and where and how, tracing the code line by line

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
java says that when an action occures actionPerformed will be invoked . i want to know where it gets invoked?
please help.

 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go and look for the ActionEvent class, and find its inheritance hierarchy. Now look up its superclass and look for its subclasses. You will find there are all sorts of events which can happen. There are events when a GUI becomes visible, comes to the front, is resized, has the mouse travel across it, etc., etc. In fact a GUI fires off hundreds of events per minute or maybe even per second. Each event travels through the different panes of the top level container, and also through all Components with the same location on screen as the event. The events will disappear off the back (root pane) of the top level container and disappear into cyber‑limbo never to be seen again (except possibly by garbage collection programs). But somewhere on that journey, the event can be listened for. Add an ActionListener to a button, and that listener will intercept all action events passing through that button. When that happens, the one method in ActionListener will be called. The process is similar for all sorts of event; you will also find that if you go a bit higher in the inheritance tree for events, you find this and it has all sorts of different subclasses, representing even more kinds of different events for other circumstances.

The different events occur when different things happen. Action Event, which is listened for by Action Listeners, occurs when you click a button with the mouse, or use the enter key inside a text field, or similar actions.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A simplistic overview.
You add an ActionListener to a JButton, which adds it to a List<ActionListener> in the button.
When you click the JButton this will eventually result in the fireActionPerformed method of AbstractButton being called.
That method essentially iterates over all the ActionListeners in the List it has and calls the one (actionPerformed) method.

If you want to know where the fireActionPerformed is called from then debug it and stick a breakpoint at the start of the method.  You'll see the call chain for the entire event.
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic