I'm writing a simple game application and i'm stuck on this problem.
- pwait and pmain are 2 panels
- frame is the main frame
"create" is a button, inside the pmain Panel, and this is the action performed when it gets clicked:
Here is the 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 the max number of guessers"));
nome = JOptionPane.showInputDialog(null, "give the name of the 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();
}
// AND HERE IS THE PROBLEM:
if(!UA.apriPartita(n, nome))
System.out.println("ERR creazione partita"); // TODO
refreshPartite();
}
});
UA is the logic-class behind the this interface class. The called method "UA.apripartita(..)" works fine and it does a lot of things. The problem is: i want the interface to repaint and show the pwait panel when the "create" button is clicked, but it doesn't UNTIL the method UA.apripartita(..) is returned (and, i guess, the ActionPerformed function is also returned?).
Effectively, i also tried removing that UA.apripartita(..) method call and it just works fine. Why it doesn't work when the method is inside it?
Thanks in advance!
ps. already tried putting in some frame.repaint() or frame.invalidate() but they seem to do nothing..
pps. any other good advide about this code is welcome!