EventQueue. invokeLater (new Runnable ())

Source: Internet
Author: User

Public class EventQueueextends ObjectEventQueue is a platform-independent class that includes events from the underlying same-bit classes and trusted application classes in the queue. It encapsulates the asynchronous event Assignment Mechanism, which extracts events from the queue and assigns these events (events are assigned as parameters) by calling the dispatchEvent (AWTEvent) method for this EventQueue ). The special behavior of this mechanism is related to implementation. The only requirement for assigning events that are actually in the queue (note that events that are being sent to EventQueue can be merged) is to assign events in order. That is to say, you cannot assign multiple events from the queue at the same time. The assignment order is the same as the order in which they are queued. That is to say, if AWTEvent A is first ranked in EventQueue than AWTEvent B, event B cannot be assigned before event. Some browsers divide the applets in Different Code bases into independent contexts and build a wall between these contexts. In such a scenario, each context will have an EventQueue. Other browsers put all the applets In the same context, which means that all the applets have only one global EventQueue. This action is related to implementation. For more information, see the browser documentation. PostEventpublic void postEvent (AWTEvent theEvent) sends a 1.1-style event to EventQueue. If an event with the same ID and event source exists in the queue, the coalesceEvents method of the source Component is called. Parameter: theEvent-java. awt. AWTEvent instance or its subclass throws: NullPointerException-If theEvent is null then getNextEventpublic AWTEvent getNextEvent () throws InterruptedException remove an event from EventQueue and return this event. This method is blocked before another thread sends an event. Returned: The next AWTEvent throw: InterruptedException-if any thread interrupts this thread, when the program peekEventpublic AWTEvent peekEvent () returns the first event on EventQueue without removing it. Return: the first event ---------------------------------------------------------------------------------- peekEventpublic AWTEvent peekEvent (int id) returns the first event with the specified id (if any. Parameter: id-the id of the required event type. Return the first event of the specified id. If no such event exists, null events dispatchEventprotected void dispatchEvent (AWTEvent event) is returned to assign an event. The way to assign an event depends on the event type and the type of the event's source object: The event Type source type assigns all ActiveEvent events. dispatch () Other Component source. dispatchEvent (AWTEvent) Other MenuComponent source. other non-action (ignore) parameters of dispatchEvent (AWTEvent): event-java. awt. the AWTEvent instance or its subclass throws: NullPointerException-if the event is null, it starts from the following versions: 1.2 running getMostRecentEventTimepublic static long getMost RecentEventTime () returns the timestamp of the most recent event (if any), which is assigned from EventQueue (which is related to the thread being called. If an event with a timestamp is currently being assigned, its timestamp is returned. If no event is assigned, the initialization time of EventQueue is returned. In the current JDK version, only InputEvent, ActionEvent, and InvocationEvent have timestamps. However, future JDK versions may add timestamps to other event types. Note that this method should be called only from the designated thread of the Application Event. If this method is called from another thread, the current System time is returned (reported by System. currentTimeMillis ). Return: The last InputEvent timestamp, The ActionEvent or InvocationEvent to be assigned. If this method is called on a thread different from the event-assigned thread, System is returned. currentTimeMillis () starts from the following versions: 1.4. For more information, see InputEvent. getWhen (), ActionEvent. getWhen (), InvocationEvent. getWhen () implements getCurrentEventpublic static AWTEvent getCurrentEvent () to return the event that is being assigned by EventQueue (which is related to the thread being called. This method is useful only when a method needs to access events, but is not designed to accept events as parameters. Note that this method should be called only from the event-assigned thread of the application. If this method is called from another thread, null is returned. Return: The currently assigned event. If the thread that calls this method is not the event-assigned thread, null is returned starting from the following version: 1.4 pushed pushpublic void push (EventQueue newEventQueue) replaces the existing EventQueue with the specified event queue. Any pending events are transmitted to EventQueue for processing. Parameter: newEventQueue-The EventQueue (or its subclass) instance to be used throw: NullPointerException-If newEventQueue is null, it starts from the following versions: 1.2. For more information, see pop () ------------------------------------------------------------------------------ popprotected void pop () throws EmptyStackException stops using this EventQueue to assign events. Any pending events are transmitted to the previous EventQueue for processing. Warning do not declare this method as synchronized in the subclass to avoid deadlocks. Throw: EmptyStackException-if you have not previously performed the push operation on this EventQueue from the following versions: 1.2. For more information, see: push (java. awt. eventQueue) -------------------------------------------------------------------------------- isDispatchThreadpublic static boolean isDispatchThread () returns true if the thread being called is the designated thread of the current AWT EventQueue. Use this call to ensure that the given task is being executed (or not executed) on the current AWT EventDispatchThread ). Return: If the given task is running on the designated thread of the current AWT EventQueue, true is returned. Starting from the following versions: 1.2 running invokeLaterpublic static void invokeLater (Runnable runnable) causes runnable run methods to be called in the designated thread of the system EventQueue. Parameter: runnable-Runnable object. Its run method should be executed synchronously on EventQueue starting from the following versions: 1.2. For more information, see invokeAndWait (java. lang. runnable) invoke invokeAndWaitpublic static void invokeAndWait (Runnable runnable) throws InterruptedException, InvocationTargetException causes runnable's run method to be called in the designated thread of the system EventQueue. This occurs only after all pending events are processed. The call is blocked before this occurs. If a thread is assigned from an event for calling, this method will throw an Error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.