hey guys, i am on the process of finishing this program it is supposed to be finished already only that I do not know how am i going to repeat the whole game after the user chooses the Yes Button from the message box. i hope u could help me guys...

Dani AI

Generated

Good point from — centralize the game-start logic so the same method is called for the first play and for every replay. Put all setup (generate a new secret, reset attempt counters, clear the guess history and UI) into one startNewGame() or reset() method in a controller or model class, then call that from the Yes action. This avoids recreating windows, re-registering listeners, or duplicating initialization code.

A minimal pattern (Swing + JOptionPane) that matches the message-box flow shown in the thread:

private void startNewGame() {
    model.generateSecret();
    model.resetAttempts();
    view.clearBoard();
    view.enableInput(true);
    view.repaint();
}

// hook for the confirm dialog or a Yes button
int opt = JOptionPane.showConfirmDialog(frame, "Play again?", "Play again",
        JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
    controller.startNewGame();
}

Troubleshooting notes and cautions drawn from common pitfalls: do not call main() to restart the app or create a new frame each time without disposing the old one (memory leaks). Avoid adding the same ActionListener repeatedly — register listeners once and have them invoke the controller. Do not run long game logic on the Event Dispatch Thread; use a background thread or SwingWorker for heavy checks so the UI stays responsive. Finally, test several repeated plays to ensure state is fully cleared (secret, attempts, UI) and no duplicate listeners or accumulating resources remain.

Well, assuming you structured your program decently... just get your YES button ActionListener to call the appropriate method of whichever object is controlling the game (flow).

If not, structure it that way - so that the same method can be called to begin the game, whether you're playing the first game or the 100th game.

Well, assuming you structured your program decently... just get your YES button ActionListener to call the appropriate method of whichever object is controlling the game (flow).

If not, structure it that way - so that the same method can be called to begin the game, whether you're playing the first game or the 100th game.

thanks a lot you are a big help. muah :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.