Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1159 > unrolled thread

Fwd: How do you time rese

Started by"Phil Powell" <phil.powell@THRWHITE.remove-dii-this>
First post2011-04-27 15:31 +0000
Last post2011-04-27 15:31 +0000
Articles 2 — 1 participant

Back to article view | Back to comp.lang.java.gui


Contents

  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

#1159 — Fwd: How do you time rese

From"Phil Powell" <phil.powell@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
SubjectFwd: How do you time rese
Message-ID<1173729511.933376.200980@p10g2000cwp.googlegroups.com>
  To: comp.lang.java.gui
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

[toc] | [next] | [standalone]


#1165 — Re: Fwd: How do you time

From"Phil Powell" <phil.powell@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
SubjectRe: Fwd: How do you time
Message-ID<1173794620.085307.168190@p10g2000cwp.googlegroups.com>
In reply to#1159
  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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web