Content deleted Content added
Isaidnoway (talk | contribs) →See also: removed red link see also there is nothing to see |
MOS:HEAD |
||
Line 3:
The events are primarily update events that cause user interface [[Software componentry|components]] to redraw themselves, or input events from [[input device]]s such as the mouse or keyboard. The AWT uses a single-threaded painting [[Model (abstract)|model]] in which all screen updates must be performed from a single thread. The event dispatching thread is the only valid thread to update the visual state of visible user interface components. Updating visible components from other threads is the source of many common [[Software bug|bugs]] in Java [[Computer program|programs]] that use [[Swing (Java)|Swing]].<ref>This problem is not specific to Java [[Swing (Java)|Swing]]. There is the same issue in most [[Widget toolkit]]s, as for example [[Windows Forms]], where the [[BackgroundWorker]] class performs the same purpose as [[SwingWorker]] in Java.</ref> The event dispatching thread is called the '''primordial worker''' in [[Adobe Flash]] and the '''UI thread''' in [[Standard Widget Toolkit|SWT]], [[.NET Framework]] and [[Android (operating system)|Android]].
== Message
A software application normally consists of multiple threads and a single GIT data structure. This means GIT is a shared data structure and some synchronization is needed to ensure that only one thread accesses it at a time. Though [[Abstract Window Toolkit|AWT]] and [[Swing (Java)|Swing]] expose the ([[Thread safety|thread unsafe]]) methods to create and access the GUI components and these methods are visible to all application threads, likewise in other GUI frameworks, only a single, Event Dispatching thread has the right to execute these methods.<ref>{{cite web
Line 32:
There are various solutions for submitting code to the EDT and performing lengthy tasks without blocking the loop.
===Component
GUI components support the lists of callbacks, called Listeners, which are typically populated when the components are created. EDT executes the listeners when user excitates the components somehow (button is clicked, mouse is moved, item is selected, focus is lost, component resized and so on.)
Line 89:
* <code>android.os.AsyncTask</code> - [[Android (operating system)|Android]]
===Modal
SwingWorker is normally created for a lengthy tasks by EDT while handling callback (Listener) events. Spawning a worker thread, EDT proceeds handling current message without waiting the worker to complete. [https://stackoverflow.com/questions/3028842/how-can-swing-dialogs-even-work Often, this is not desirable.]
Line 97:
<syntaxhighlight lang="java">
▲ public void actionPerformed(ActionEvent e)
▲ button.setText("Sleeping...");
▲ text = (String)Worker.post(new Task()
▲ public Object run() throws Exception
}
});
▲ Thread.sleep(10000);
▲ return "Slept !";
▲ catch (Exception x) ...
</syntaxhighlight>
|