java - repaint isn't working inside Action Performed -


i'm writing simple game application , i'm stuck on problem.

  • pwait , pmain 2 panels
  • frame main frame

"create" button, inside pmain panel, , action performed when gets clicked:

here code:

// action: create new game     create.addactionlistener(new actionlistener() {          public void actionperformed(actionevent e) {             if(ua.alreadyopen()) {                 joptionpane.showmessagedialog(null,"already open game!");                 return;             }              int n = 0;             string nome = null;              try {                 n = integer.parseint(joptionpane.showinputdialog(null, "give max number of guessers"));                 nome = joptionpane.showinputdialog(null, "give name of game");                 if ( n < 1 || nome == null) system.out.println("maininterface: input problems"); // todo ...                  frame.setcontentpane(pwait);                 pwait.setvisible(true);                 pmain.setvisible(false);                 frame.pack();             } catch (numberformatexception e1) {                 // ???                 e1.printstacktrace();             } catch (headlessexception e1) {                 // ???                 e1.printstacktrace();             }                  // , here problem:                 if(!ua.apripartita(n, nome))                      system.out.println("err creazione partita"); // todo                 refreshpartite();          }     }); 

ua logic-class behind interface class. called method "ua.apripartita(..)" works fine , lot of things. problem is: want interface repaint , show pwait panel when "create" button clicked, doesn't until method ua.apripartita(..) returned (and, guess, actionperformed function returned?).

effectively, tried removing ua.apripartita(..) method call , works fine. why doesn't work when method inside it?

thanks in advance!

ps. tried putting in frame.repaint() or frame.invalidate() seem nothing..

pps. other advide code welcome!

this because actionperformed(...) method runs under control of ui main event thread. so, ui can't refreshed while ua.apripartita() running. if method designed run long time (say more half second, users don't long delays between actions , effects), should think using multithreading (if method must interact ui, think swingworker).


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -