• 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

firing an event when it has not been fired

 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Does anyone know of a way to hook up let's say an ActionListener to a Button, and then have that event fire automatically even though noone has clicked it? I guess this seems like a strange thing to do, but I need to know if I can do this. Some sample code would help. Thanks in advance!!!
Barry
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry,
I have not yet found out how to do it nicely. What I do in the short term is to override the component and handle the event myself. What this allows me to do is to call the processEvent method of my component. All AWT components have protected access to their processEvent methods; therefore, I can't call them unless I extend the components. I usually override the processEvent method with a public accessor. That way I won't have any trouble calling it from whereever I like ...
Here is a simple example showing the concept:

Hope this helps,
Manfred.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may be a cheezy work-around, but the way I do this is by using anonymous inner-classes. I use adapter classes as event listeners for my components. Inside of these inner classes I call a method specific to that event and that component. In inner class I get the members of the event object and pass them as parameters to the method that actually handles the event. That way if I need to call that event I can just call it with parameters and I don't have to create an event object. So if I want to force that event to occur, I can just call the method that I want and off I go.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic