Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1165
| From | "Phil Powell" <phil.powell@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Fwd: How do you time |
| Message-ID | <1173794620.085307.168190@p10g2000cwp.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <1173729511.933376.200980@p10g2000cwp.googlegroups.com> |
| Date | 2011-04-27 15:31 +0000 |
| Organization | TDS.net |
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
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Find similar | Unroll thread
Fwd: How do you time rese "Phil Powell" <phil.powell@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000 Re: Fwd: How do you time "Phil Powell" <phil.powell@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000
csiph-web