I am having a GUI of login screen. Whenever i press the login button the user name and password is checked against entry in an online mysql database,i’m extracting all this information from database in actionPerformed() method of the login button.Problem is while program is fetching data from database the GUI freezes.I googled my problem and found that i should use SwingWorker but being a newbie i didn’t get how to use SwingWorker for my purpose.
Share
First of all, declare a member variable in your class (it could be in your GUI class) of type
SwingWorkerlike this:Then initialize the variable in your initialization code (constructor, onShow method event handler, etc) like this:
Then, in your
actionPerfomedmethod, call theSwingWorker‘s execute method:If done correctly, the GUI shouldn’t freezee after the button press event