1

enter image description here

I've a form (as in the screenshot) that has the login part should be disabled until the user hit "Run Server".

What the "Run Server" button do is calling another class: Server.getInstance().startMe();

What I want to do is after calling the another class, is to enable the login part, but the problem after hitting the "Run Server" button, the whole form becomes out of my control and didn't accept any input from me, and it even didn't enable the login part!

The "Run Server" code:

    private void runServerButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
    Server.getInstance().startMe();
    runServerButton.setEnabled(false);
    userLoginEnterBottun.setEnabled(true);
    useridLoginTextField.setEnabled(true);
    passwordLoginTextField.setEnabled(true);
}   
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Hisham Ramadan
  • 315
  • 1
  • 5
  • 11
  • Could you also provide the code with your actionListener and how you add it to the button, please? – ithofm May 23 '14 at 09:13

1 Answers1

3

You need to launch run server part in separate thread, Currently it is holding your EDT and that is the reason your GUI becomes un-responsive:

private void runServerButtonActionPerformed(java.awt.event.ActionEvent evt) {   
    new  Thread() {                                              
       public void run() {
         Server.getInstance().startMe();
       }
    }.start(); 
    runServerButton.setEnabled(false);
    userLoginEnterBottun.setEnabled(true);
    useridLoginTextField.setEnabled(true);
    passwordLoginTextField.setEnabled(true);
} 
Sanjeev
  • 9,876
  • 2
  • 22
  • 33
  • @HishamRamadan Glad it helped you, kindly select tick mark. have fun coding :) – Sanjeev May 23 '14 at 09:15
  • Sanjeev is absolutely right. Just keep in mind that whatever you do with startMe() (perhaps starting your server) might not be finished when you log in through the form. – ithofm May 23 '14 at 09:29