|
Worker and Timer Threads
An Introduction with Examples in Java |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
SwingWorker
SwingWorker
execute() method
doInBackground() is called
PropertyChangeEvents
done() is called
SwingWorker:
setProgress() to generate
PropertyChangeEvent objectspublish() to cause the process()
method to be calledPropertyChangeListener:
propertyChange() messages
and check the name (e.g. "progress", "state")
SwingWorker:
isCancelled()
SwingWorker:
cancel() method to change its stateSwingWorker Threads
execute() is called in.doInBackground() is
called in.process() and done()
are called in (and the thread that is used to
inform PropertyChangeListener objects).
javax.swing.Timer
addActionListener() (either explicitly
or using the constructor)start() or restart()
ActionListener