|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.swing.SwingWorker
public abstract class SwingWorker
Implementation of SwingWorker from SUN with interrupting capability.
Ensures executing of long - running tasks, that are invoked from Swing (AWT event) thread in separate thread rather than in Swing thread. So Swing thread is not blocked, the Swing components can be repainted and the events served.
Class has two important methods: doInBackground()
and
done()
. The first is invoked in separate thread after SwingWorker
starts and it does not block Swing thread. This method should be used to
long-runnning task executing (such as communication with server). The second
is invoked when doInBackground()
method finished and it runs in
Swing (AWT event thread). This method should be used to set values to Swing
components.
Method get()
blocks until doInBackground()
is running
and then returns value computed in this method.
Method interrupt()
interrupts the code executing in
doInBackground()
method.
... // here we are usually in Swing (AWT event) thread SwingWorker worker = new SwingWorker () { protected Object doInBackground () { // this method is running in separate thread // here comes the long-running code // (communication with server, etc.) } protected void done () { // this method is running on Swing (AWT event) thread // here comes code to set values to Swing components } }; worker.start(); ...
Constructor Summary | |
---|---|
SwingWorker()
Creates a new instance of SwingWorker. |
Method Summary | |
---|---|
protected abstract java.lang.Object |
doInBackground()
In overriden method in the subclass here comes the long-runnning code. |
protected void |
done()
In overriden method in the subclass here comes the code to set values computed in doInBackground() method to Swing components. |
java.lang.Object |
get()
Returns value computed in doInBackground() method. |
void |
interrupt()
Interrupts the code executing in doInBackground() method. |
void |
start()
Starts this SwingWorker (invokes doInBackground() in separate
thread). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SwingWorker()
Method Detail |
---|
public void start()
doInBackground()
in separate
thread).
public java.lang.Object get()
doInBackground()
method. This method
blocks until doInBackground()
is running.
public void interrupt()
doInBackground()
method.
protected abstract java.lang.Object doInBackground()
protected void done()
doInBackground()
method to Swing components. This
method is invoked in Swing (AWT event) thread. In this implementation
does nothing.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |