In the HangManPane
class, you could to provide a playAgain
method, for example...
protected void playAgain(String msg) {
int result = JOptionPane.showConfirmDialog(this,
"<html>" + msg + "<br>Do you want to play again?",
"Play Agaion",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
switch (result) {
case JOptionPane.YES_OPTION:
setModel(new DefaultHangManModel("Your new secret word"));
break;
default:
SwingUtilities.getWindowAncestor(this).dispose();
break;
}
}
In the HangManListener
implementation, you would simply then call this method, for example...
@Override
public void wonGame(HangManModelEvent evt) {
playAgain("You won");
}
@Override
public void lostGame(HangManModelEvent evt) {
playAgain("You lost");
}