I have a guessing game where the user enters a number from 1 to 10 and tries to guess the right one.
I have a button in a window that starts a new game:
btnPlayAgain = new JButton("Play Again!");
btnPlayAgain.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newGame();
}
});
btnPlayAgain.setBounds(146, 115, 141, 21);
getContentPane().add(btnPlayAgain);
btnPlayAgain.setVisible(false);
I want the user to press Enter and have the button get clicked.
This is all my code:. This is what the window with the play again button looks like:
How can I get that play again button to click when the user hits that button?