Results 1 to 2 of 2
  1. #1
    Miromancer is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default SwingWorker progress?

    Hello,

    I would like to know if there is any way to get progress even if I want to keep GUI and core separated.
    In the doinBackground() method I call a method from a core class (I load some files and initialize a game). How do I pass the progress to the Worker if time remaining in not known? Or at least I do not know it.

    Here is a snippet:
    Java Code:
      SwingWorker<String, Object> worker = new SwingWorker<String, Object>() {
    
                        @Override
                        protected String doInBackground() throws Exception {
                            GameBegin();
                            return "Start Game";
                        }
                       ...
                    };
                    worker.execute();
    In the GameBegin I call the constructor of the class Game and initialize the whole thing. How do I get progress from the class Game to the main class where the Worker is?

    Thanks for all pieces of advice.

    Mirek

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: SwingWorker progress?

    Since you don't know the time remaining, I can't see how you'll be able to pass it anywhere. Perhaps you are able to get another surrogate marker of completeness such as bytes or files processed? Otherwise about all that I can see you can do based on the code and information provided is to tell the calling code when the SwingWorker has started and when it has finished, and to do that you could add a PropertyChangeListener to the SwingWorker.

Similar Threads

  1. When do I use SwingWorker?
    By TacoManStan in forum AWT / Swing
    Replies: 8
    Last Post: 10-24-2011, 01:40 AM
  2. SwingWorker
    By 3.14.TR in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-14-2011, 05:53 PM
  3. Using SwingWorker
    By viking90 in forum New To Java
    Replies: 1
    Last Post: 04-24-2010, 10:17 AM
  4. SwingWorker question
    By cotarelo in forum Threads and Synchronization
    Replies: 16
    Last Post: 03-23-2010, 12:29 PM
  5. swingworker
    By musiigedeo in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 01:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •