Problem implementing Java Swing worker -


i've learned executing swing background tasks , i'm starting experiment i'm having little trouble implementation. code retrieves image , returns result (an integer) indicates whether image retrieval successful result = 0 or unsuccessful result = -1. here problem, retrieving result soon. can see statements in createimage method in code below executing after result read in done() method. guess thought done method not execute until createimage done. here code below:

new swingworker<int[], void>() { int result = -1; @override protected int[] doinbackground() throws exception {  // todo auto-generated method stub return createimage();  //returns integer array of size 1 indicating result                     }  protected void done() { try { result = get()[0];  //this result being read before createimage done                           //executing.  why? thisapplet.setcursor(new cursor(cursor.default_cursor)); tree.setenabled(true); if (result == -1){     tree.setselectionpath(null);      return; }    } catch (interruptedexception e) {                                           e.printstacktrace();     } catch (executionexception e) {                                       e.printstacktrace();     }       } }.execute(); 

the done method not execute until doinbackground method completed. there must else going on here. guess might calling done , doinbackground instead of run()? if not, try find issue creating sscce.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -