Is it possible to fire system events like ActionEvent or MouseEvent ?
Most of the constructors of these events require the event source and id of the event.
So lets say in some simulation project, I need a particular button to be clicked n number of times at m intervals. So can I create an ActionEvent object with that button as source and then somehow fire the event at regular intervals instead of manually having to press the button.
Thanks Greg for the reply. But I think I was looking for a different answer.
I was trying to understand the meaning of an event.
I got the definition of an event as:
Events are objects or messages used when a software components wants to notify a state change to other components.
As per my understanding the classification can be of 3 types.
1. System generated GUI events (All the events which inherit from java.awt.AWTEvent class as of JDK1.1 2. System generated non-gui events. I am really not sure how this is possible or don't have an example for this. But from the design perspective this shud be possible. Let me guess something like a task manager. 3. User generated events. This can be a Event Source implementing observer design pattern in which event handlers can register with the event source for notification.
If this classification is correct, then do we follow any standards for all the three categories of events.
I mean all exceptions have a common root, all threads have a common root, all objects have a common root. So why not a common root for all kinds of events ?
There should be a standard mechanism for creation as well as firing of events.
Secondly, if system generated GUI events r something which should have been generated only by System, then why do we have public constructors for all such events. :roll:
I was again thinking over the difference between creating an instance of event and firing of an event. What can a user do by creating an instance of a system event, if he cannot fire it ? or is there any way to fire the event.
There is a common class parent of all the Events in the JDK 1.0 Event Model. It is java.awt.Event. This model is obsolete. You can read read about it here thanks to R.G.Baldwin. You can also read about the advantages of the new Delegation Event Model in JDK 1.1 here. The common class for all the events in the Delegation Event Model is java.util.EventObject.
The use of Observer/Observable in Java to implement the publish-subscribe pattern is dated in JDK 1.0. A that time the DEM model was not out. DEM goes beyond MVC because encapsulates what has changed in an Object: the event. And we have a hierarquy of events to express different events.
The constructors are public because they need to be called from outside the package they were declared.
The short answer is that you have the ability to contruct and fire the events you need to do so; while others events are "automatically" created and managed: Low level events represent interactions of the user with the window, mouse or keyboard. The OS passes messages for this interaction to the Java runtime who contructs and fires the apropiate events. Semantic events has meaning regardless how they were spawned. When an ActionEvent signals that a button was pressed you are interested in the meaning of that hit for the program, not in knowing if the mouse or keyboard was involved. Some of the semantic events can be generated without user interaction, they can be generated programatically via the apropiate methods. Like AbstractTableModel.fireTableXXX
Thanks Jose for the explanation. I now have got the answer to my questions. For all AWTEvents, the general procedure to fire events is calling processEvent method, which is supported by all the AWT & Swing Components. I tried it in my code and it worked. The source is provided below.
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking