Re: Fwd: How do you time
To: comp.lang.java.gui
GOT IT!
/**
* Use {@link #setWebBrowserURL} using a local {@link
com.ppowell.tools.ObjectTools.SwingTools.Task}
*/
protected void processTask() {
Task task = new Task() {
public Void doInBackground() {
int progress = 0;
while (!
SimpleBrowser.this.builder.hasLoadedWebpage && progress < 100) {
SimpleBrowser.this.statusBar.setMessage("Attempting to load " +
SimpleBrowser.this.getURL().toString());
this.setProgress(progress);
progress++;
}
SimpleBrowser.this.setWebBrowserURL();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {}
if (SimpleBrowser.this.builder.hasLoadedWebpage) {
SimpleBrowser.this.statusBar.setMessage("Done");
}
return null;
}
};
task.addPropertyChangeListener(SimpleBrowser.this);
task.execute();
}
All I had to do was stuff everything into doInBackground() which
created a worker thread out of the entire routine, stuffing
progression and thread sleeping in between them!
Phil
On Mar 12, 3:58 pm, "Phil Powell" <phillip.s.pow...@gmail.com> wrote:
I tried using a Task class I wrote which extends SwingWorker<Void,
Void>:
Task task = new Task() {
public Void doInBackground() {
SimpleBrowser.this.statusBar.setMessage("Attempting to load " +
SimpleBrowser.this.getURL().toString());
int progress = 0;
//Initialize progress property.
setProgress(0);
while (progress < 10 && !
SimpleBrowser.this.builder.hasLoadedWebpage) {
// SLEEP FOR 1 SECOND
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
progress++;
setProgress(Math.min(progress, 10));
}
SimpleBrowser.this.setWebBrowserURL();
return null;
}
public void done() {
SimpleBrowser.this.statusBar.setMessage("Done");
}
};
task.addPropertyChangeListener(SimpleBrowser.this);
task.execute();
Problem is now that it will do the following:
1) Show status of "Attempting to load.."
2) Show status of "Done"
3) Load the page into JEditorPane
The order I want is this:
1) Show status of "Attempting to load.."
2) Load the page into JEditorPane
3) Show status of "Done"
How do I accomplish this?
Phil
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24