Ive been working with my personal pong game and came across a very annoying bug that i haven't been able to fix. If i run the game everything works fine. Once the game is over it is supposed to prompt you to enter your name. The name should then bed stored as a String. Then it tells you your name and your score. But instead of that happening it doesn't store the user input a just stays blank. Some please help me!!!
@SuppressWarnings("resource")
public void replay() {
JFrame frame = new JFrame("input");
JOptionPane.showInputDialog(frame, "what is your name player 1? ");
String playerName1 = new String();
new Scanner(System.in);
JOptionPane.showConfirmDialog(null,
"Name: " + playerName1 + " Score: " + scorePlayer1 , "Player scores",
JOptionPane.DEFAULT_OPTION);
String playerName2 = new String();
JOptionPane.showInputDialog(frame, "what is your name player 2? ");
JOptionPane.showConfirmDialog(null,
"Name: " + playerName2 + " Score: " + scorePlayer2 , "Player scores",
JOptionPane.DEFAULT_OPTION);
int n = JOptionPane.showConfirmDialog(null,
"Would you like to play again?",
"Pong",
JOptionPane.YES_NO_OPTION);
if (n == 0){
setup();
} else {
System.exit(0);
}
}