I am loading a JFrame AdminFrame (with add user and addLocation button on it) when the user click’s addUser button the new JFrame addUser loads and takes user information. When the information is submitted to server it takes some time(because server is web-based) during that time both of my panels got stuck…what i want is to make AdminFrame clickable and use-able so that user can add new user or can add location…
Here is my AdminPanels add button’s template code…not writing original code because original code to is too messy..
public class AdminPanel extends JFrame{
public AdminPanel(){
Initalize();//Do Initalize Stuff
}
public void addBtnActionPerformed(){
//load Child Form
}
}//End of class
Now here is my AddUser Panel’s adduser button Templete code Orignal code to too messay..
public class AddUser extends JFrame{
public AddUser(){
Initalize();//Do Initalize Stuff
}
public void addUserBtnActionPerformed(){
/*
take user's form input values make a http request send to server
get response...now what i have to do here to make parent form clickable?
*/
}
}//End of class
You need to use a SwingWorker to dispatch your heavy/lengthy operations into another Thread, allowing the UI-Thread(EDT) to respond to events.
Here is a very simple code showing how SwingWorker can be used (connection to a server is here emulated by a bunch of
Thread.sleep()):