java - Use swingWorker with other classes -


i'm starting work java guis , have problems swingworker: i'm trying simple ui start server, run "slave" objects , finally, run master object managing work. define problem in master (the number of tasks do) , have progressbar in ui want update each time task done. use swingworker update progressbar, don't know how right: in background method sleeps until master wakes when task done. unfortunately doesn't work , appreciate if explain me should do.

i create swingworker in gui , add listener update progressbar:

private void jbutton5actionperformed(java.awt.event.actionevent evt) {          worker = workerupdater.getinstance();         jprogressbar1.setvalue(0);         worker.addpropertychangelistener(this);         worker.execute(); 

this swingworker:

public class workerupdater extends swingworker<void, integer> {      private static workerupdater instance;     private int progress;     private boolean changed = false;      public int getprogreso(){         return this.progress;     }      public void setprogreso(int p){         this.progress = p;         changed = true;     }      public static workerupdater getinstance(){         if(instance == null)             instance = new workerupdater();         return instance;     }      @override     protected void doinbackground() throws exception {         while(progress < 100){             if(changed){                 setprogress(math.min(progress, 100));                 changed = false;             }         }         return null;     }  } 

and want update value of progress bar when task done in other class (client):

    public boolean taskisdone(string taskid, object[] retval) throws remoteexception {          system.out.println("client: taskisdone(): old task: " + taskid);          this.donetasks++;         this.progress = ((double) math.ceil(donetasks / totaltasks)).intvalue();          synchronized (tasksynch) {             worker.setprogress(progress);             this.results.put(taskid, retval);             task_count--;             tasksynch.notify();         }          system.out.println("client: task finished: " + taskid);          return true;     } 

the problem value of progress in client class changes value progress bar doesn't.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -