Possible to update gui with new thread AND halt program execution?

Hello, my problem is the following:
I have a JButton that performs a sql query and retrieves information from a database, while this is done I would like to update a JLabel with information that the query is in progress. I have got this working but the problem is that I would like the main thread to wait until the search thread has finished execution, of course this inflictes with the gui update... look below for code:
//class that synchronizes the threads when retrieving data
public class SynkroniseradVektorKlass
   private Vector verde = new Vector();
   private boolean inteFerdig=true;
   public SynkroniseradVektorKlass(boolean inteFerdig)
      this.inteFerdig=inteFerdig;
   //sets the value of the vector
   public synchronized void settVerde(Vector verde)
       this.verde=verde;
       //set the boolean to false so the wait() can be avoided
       inteFerdig=false;
       //notify all threads that we have retrieved a value
       notifyAll();
    public synchronized Vector returneraVerde()
        //if no value has been retrieved, wait
        if(inteFerdig)
           try
                wait();
           catch(InterruptedException ie){}
    //when waiting is done, return value
    return verde;
//class that retrieves data and prints it
//not really necessary here but useful to check that the SynkronisedVektorKlass
// works
public class TradHarDataKommit extends Thread
   private SynkroniseradVektorKlass hemtaData;
   public TradHarDataKommit(SynkroniseradVektorKlass hemtaData)
      this.hemtaData=hemtaData;
   public void run()
       System.out.println("Thread two begins");
       System.out.println("data == "+hemtaData.returneraVerde());
       System.out.println("Thread two done");
//class that communicates with the database and retrieves the data
public class NyTradKorSQLSats extends Thread
   private String sqlSats;
   private java.util.Timer timer;
   private JLabel label;
   private JFrame ram;
   private SynkroniseradVektorKlass tilldelaData;
   public NyTradKorSQLSats(String sqlSats,java.util.Timer timer,JLabel ,SynkroniseradVektorKlass tilldelaData,JFrame ram)
      this.sqlSats=sqlSats;
      this.timer=timer;
      this.label=label;
      this.tilldelaData=tilldelaData;
      this.ram=ram;
   public void run()
       System.out.println("Thread one begins...");
       //executes the sql query and retrieve data
       tilldelaData.settVerde(klient.korKlient(sqlSats));
       //end the timer that updates the JLabel
       timer.cancel();
       label.setText("");
       ram.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
       System.out.println("Thread one done...");
//in actionPerformed
java.util.Timer timer = new java.util.Timer();
//boolean used to show when execution is done          
boolean sokningInteFerdig=true;
//class that holds a value retrieved from database and make sure that
//everything is synchronized
SynkroniseradVektorKlass dataFranSokning = new SynkroniseradVektorKlass(sokningInteFerdig);
//class that retrieves information from dataFranSokning     
TradHarDataKommit skrivUtData = new TradHarDataKommit(dataFranSokning);
//class that executes sql query, with arguments sql, a timer that updates
//the JLabel,the JLabel,the dataholding class, and a JFrame     
NyTradKorSQLSats korTrad = new NyTradKorSQLSats("1Select namn from kundregister where kundnr=1",timer,statusRad,dataFranSokning,this);
//a TimerTask class that updates the JLabel               
TimerStatusRad task1 = new TimerStatusRad(statusRad,"Searching...",this);
TimerStatusRad task2 = new TimerStatusRad(statusRad," ",this);
//starts timer task1 directly and restarts every second
timer.schedule(task1,0,1000);
//starts timer task 2 after a second and restarts every second after     
timer.schedule(task2,1000,1000);
//set the sqlthread to daemon
korTrad.setDaemon(true);
//starts the thread                         
korTrad.start();
//I would like that the program halts here until korTrad is done
//because the data retrieved are to be used further in the program
//There is no point in using join(); because this would halt the update of the guiif anyone got any ideas how to solve this please help me
ps. sorry about my english, its not my native language

Was not able to review all of your code. But take a look at wait() and update() methods - they should solve what you need.
Denis Krukovsky
http://dotuseful.sourceforge.net/

Similar Messages

Maybe you are looking for

  • Zoom Control not appearing in Standard Toolbar (CR2008 - SP1)

    In Crystal XI (and prior versions), the Zoom control would appear in the standard toolbar. I was able to either select (from the drop down list) or type in the level of zoom.  Now this control is no longer showing on the toolbar.  Is there a setting

  • Enhancement for MIRO & F110

    Hi, I need help for the following issue. 1. There is a Purchase Price Variance PL Account which doesnt has Cost element and during MIRO while posting with price variance posting happens to same PL Account which should take the Profit center of the De

  • URL class is not being garbage collected

    I have created two instances of the URL class to specify a file location for each image. I use com.symantec.itools.javax.swing.icons.ImageIcon class to display images specified by each URL instance as icons inside a button. The setImageLocation metho

  • Posting from FBCJ to Asset

    Hi All, Please let me know that posting from FBCJ(Cash Journal to Asst directly is possible.when i go to FBCj there is a filed for asset posting from there but when i put asset no. there system gives error massege-Auxiliary account assignt for asset

  • After running adstrtal.sh with error code 0, unable to login

    Dear All I have successfully installed 11i on SLES 9. After installation, i was able to run the script adstrtal.sh successfully as root with error code 0. I get the home page with out any problem. When i tried to logon to the application, i get the f