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
-
Itunes 10.6.3 - Just update to the new Itunes and the album artwork is not sticking anymore... I upload the artwork and when I change songs and go back the art is gone. Anyone with similar issue ?
I have this issue. Album artwork was totally fine before. After this update, it is all messed up and even got messed up when transferred to my iphone.
iTunes doesn't have the artwork anymore, but then iPhone has it but shows wrong artwork with wrong albums.
Please fix! -
iPhone 4 - tried updating with new software and now it's asking me to plug it to iTunes. The problem is that my laptop is dead. Is there anything I can do now?
I Don't know if I can turn it of or do I just leave it and take it to service?
I'd appreciate some advice!Same thing happened here ~ tech guy at a local authorized Apple repair store said it had something to do with improper backup from which the restore would be made. Still have a phone that asks to be connected to Itunes but won't do anything else . . . frustrated.
-
My Iphone5 updated today with new iOS 6.1 and while doing that it has sync my phone number with my wife number in the same icloud due to which we receive each others SMS when we message each other. Anyone have idea how can I fix this issue in settings etc
Thank youMy Iphone5 updated today with new iOS 6.1 and while doing that it has sync my phone number with my wife number in the same icloud due to which we receive each others SMS when we message each other. Anyone have idea how can I fix this issue in settings etc
Thank you -
My client with autism needs to be able to speak/sing into a microphone and simultaneously hear his voice through a headset, preferably with reverb set on high. Is it possible to do this with the iPad and OS7? If so, what setup do I need? I have a SM58 type mic and-over-the ear headphones.
This implies that ODP.NET does NOT need to be installed on a client. However, I cannot find OraOPs9.dll on a machine with Client Release 9.2 installed. Should OraOps?.dll automatically come with a Client installation of 9.2 or higher?
ODP.NET needs to be installed on the client. OraOps9.dll is part of ODP.NET, not the Oracle Client.
Also, if an application is built with the 10g ODP.NET, can it be run from a machine with OraOps9.dll?
If an application is built with 10g ODP.NET, it can be run with 9.2 ODP.NET as long as you do not use any 10g APIs. The new features in 10g ODP.NET are included in the doc and the ODP.NET FAQ for your reference. -
How can I update Jdev with new JDK
I currently have JDev323 and I wonder how can I update it with new JDK 1.4.
What you should do is update the JDeveloper version that you use - 3.2 is sooooo old.
Get Oracle JDeveloper 9.0.4 and you'll have JDK 1.4 built in.
I don't remember if that feature was in 3.2 but since JDeveloper 9 you can switch the JDK - it is in the online help - do a search for the word JDK. -
I have a problem updating my graphs with new data in Illustrator. When I update them with new data each month the y and x-axis tend to change font and size.
What can be the problem? Please help me!Hi Rajasekar
You can purchase the enterprise toolkit fron NI, it includes a "database connectivity toolkit".
As regards the design pattern to do you you describe, it will depends on the refresh rate you need and the rate at which you want to write your data to the database.
I would have 2 loops :
- one acquiring the data and putting it in a queue,
- and a second that get the data from the queue, logging data to database and refreshing the graph.
If the write time to database is too long and slows down the graph refresh you place it in another loop.
Hope this helps
When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!" -
I just updated to the new Itunes and now my phone will not connect to my computor.
I updated to the new Itunes and my Iphone will not connect to my computor now?
Hi kevin n tracey,
If you are having issues with iTunes after an attempted update, you may find the following articles helpful:
iTunes 11.1.4 for Windows: Unable to install or open
http://support.apple.com/kb/TS5376
iOS: Device not recognized in iTunes for Windows
http://support.apple.com/kb/ts1538
Regards,
- Brenden -
I tried getting the update for my new iphone and now it is asking me to activate it again but won't let me, how do I fix this? I had started using it for a few hours and tried getting the update and now it won't let me activate the phone. I also can't call the helpline because it won't let me leave this screen on the phone that says "Your iPhone could not be activated because the activation server is temporarily unavailable. Try connecting your iPhone to iTunes to activate it, or try again in a couple of minutes." What it says on iTunes after I fill out the activation info is "There was a problem activating your iPhone. Please contact Verizon Wireless at 1-800-922-0204 to have this iPhone added to your account. Click Continue to be able to explore its features and the App Store." Please help this is driving me nuts!
iPhone User Guide
http://manuals.info.apple.com/en_US/iphone_user_guide.pdf -
my ipod touch 5 wount let me back in after trying to update ios with my computer and now says connect to itunes. it still wount work when i plug it in and click restore for it?
it went through the extracting software stage but then an error message saying that it encountered problems came up and it didn't restore.
-
Acrobat 7 mandatory update failing with error 16820 and blocking the use of the program
Acrobat 7 mandatory update failing with error 16820 and blocking the use of the program
Sorry I can't get the screen print to upload
It says
Mandatory Update Available
A Mandatory version of this application is available for download. Application can't continue without installing this version.
Application: Acrobat_com
Installed version: 2.0.0.0
Update Version : 2.3.0.0
Download now Quit
Release notes ( this is blank)
After selecting 'Download Now' I get the following message;
Download failed
There was an error downloading the update. Error #16820
Close -
updated ipad2 with new os half through the restore it tells me to enter a backup file password.. I never set one??
Have you encrypted the backups files from your iPad? If so, that is likely the password needed.
-
Iphoto crashes so tried the Alt start with new library and that worked. So now what? How to I get back to my pictures.
That shows you that iPhoto is working correctly and whatever issue you are having is based in your original library.
Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. -
Is there any way to upload iWeb files updates only with a 3rd party ftp program to a new hoster, e.g. Godaddy? I see no posts newer than 2007.
If you are using iWeb V 3, there are two other options for publishing the site...
http://www.iwebformusicians.com/iWeb/Publish-Website.html
Some pointers for choosing hosting...
http://www.iwebformusicians.com/iWeb/Website-Hosting.html -
hello,i have updated to the new 11,and now i tunes will not open,error pops up,says Data Execution Prevention,and other error we can not complete ur i tune request,unknown error 4002,i have uninstalled and reinstalled ,has been no help.
- Try restoring on another computer.
- Make an appointment at the Genius Bar of an Apple store.
Apple Retail Store - Genius Bar
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
-
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
-
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