Results 1 to 2 of 2
Thread: problem with typing game
- 11-20-2012, 07:19 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
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:
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 codeJava 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(); } }Last edited by beginner123; 11-20-2012 at 07:39 PM.
- 11-20-2012, 09:46 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Similar Threads
-
typing application
By beginner123 in forum New To JavaReplies: 16Last Post: 11-18-2012, 01:08 PM -
Typing into terminal
By keo in forum New To JavaReplies: 1Last Post: 03-15-2011, 09:09 AM -
Preventing errors when typing a letter into a String
By doymand in forum New To JavaReplies: 5Last Post: 10-30-2010, 06:56 PM -
I know there's an error, let me finish typing!
By Stravant in forum EclipseReplies: 1Last Post: 12-26-2009, 03:26 PM -
create a typing software-could anyone giv me help or guideline?
By javabeginner in forum New To JavaReplies: 1Last Post: 08-20-2009, 04:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks