T - the result type returned by this SwingWorker's doInBackground and get methods.
V - the type used for carrying out intermediate results by this SwingWorker's publish and process methods.
T doInBackground() - The abstract function that must be overridden.Return type is T.
Find the first N even numbers and display the results in a JTextArea where computations are done in background.
Main and event dispatch thread
Like any other java program, every swing program starts with a main method. The main method is initiated by the main thread. However, Swing components need to be created and updated on the event dispatch thread (or short: EDT). To illustrate the dynamic between the main thread and the EDT take a look at this Hello World! example.
The main thread is just used to delegate the creation of the window to the EDT. If the EDT is not initiated yet, the first call to SwingUtilities.invokeLater will setup the necessary infrastructure for processing Swing components. Furthermore, the EDT remains active in the background. The main thread is going to die directly after initiating the EDT setup, but the EDT will remain active until the user exits the program. This can be achieved by hitting the close box on the visible JFrame instance. This will shutdown the EDT and the program's process is going to entirely.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0