so i have a simple typing game where the user clicks the start button and 10 random words appear at the top of the screen. The user then has to enter these words into the texbox and press the space bar to move onto the next word. When the user is finished typing the words a message box appears saying how many errors were made.
my problem is if the user doesn't press the start button and just starts typing in the textbox and presses the space bar the words start to change at the top of the screen. i only want the words to change if the start button has been pressed.
heres the code to change the words:
int code = evt.getKeyCode(); String text=wordfield.getText(); if(code==evt.VK_SPACE) //moves to next word if space is pressed { this.jTextArea1.setText(""); if(this.WordCounter<10) { generateNextWord(); this.WordCounter++; } else { this.jTextArea1.setEnabled(false); JOptionPane.showMessageDialog(this, this.errorCount, "Game over! Errors made: ", JOptionPane.INFORMATION_MESSAGE); } return; } String entered=this.jTextArea1.getText(); //check for errors if(entered.length()<text.length()) { int positionToCheck=entered.length()-1; if(text.charAt(positionToCheck)!=entered.charAt(positionToCheck)) { errorCount++; Toolkit.getDefaultToolkit().beep(); } }
so basically i just need code that checks if the start button has been pressed then do the code above else don't do that code