Results 1 to 2 of 2
  1. #1
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default problem with typing game

    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:
    Java Code:
    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
    Last edited by beginner123; 11-20-2012 at 07:39 PM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

Similar Threads

  1. typing application
    By beginner123 in forum New To Java
    Replies: 16
    Last Post: 11-18-2012, 01:08 PM
  2. Typing into terminal
    By keo in forum New To Java
    Replies: 1
    Last Post: 03-15-2011, 09:09 AM
  3. Replies: 5
    Last Post: 10-30-2010, 06:56 PM
  4. I know there's an error, let me finish typing!
    By Stravant in forum Eclipse
    Replies: 1
    Last Post: 12-26-2009, 03:26 PM
  5. Replies: 1
    Last Post: 08-20-2009, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •