File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes firing an event when it has not been fired Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "firing an event when it has not been fired" Watch "firing an event when it has not been fired" New topic
Author

firing an event when it has not been fired

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

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
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: firing an event when it has not been fired
 
Similar Threads
FocusEvent
DOM TreeWalkers NodeIterators
forward:, or multiple handlers?
Struts action triggered by onUnload event on cloaing a browser
Has "Event Process in Action" something to do with AOP (Aspect Oriented Programming)?