Results 1 to 17 of 17
Thread: typing application
- 11-14-2012, 07:29 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
typing application
I'm trying to make a simple typing application. So far I have made a virtual keyboard with keys that light up after any keys are pressed on the physical keyboard. There is also a textarea displaying the text from the keys that are pressed.
I would like to make a game where random words appear on the screen and the user has to type the words.
I was thinking the game should record the speed and any mistakes the user makes.
so for example each game will have 10 words. After the user is finished the game a message box will pop up telling the user how long they took and how many errors they made.
I have no idea how to make this so I would appreciate any help
thanks
- 11-14-2012, 07:32 PM #2
Re: typing application
What part of this is giving you trouble? You apparently can detect key strokes and display text, so your next step is to compare what's been entered to what's displaying, right?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-14-2012, 09:03 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
Yes that is the part I am unsure of - How to display random words and compare it to whats being entered in the textarea
- 11-14-2012, 10:34 PM #4
Re: typing application
The simplest thing would be to set the text in another text field. If that's not fancy enough, you can draw strings using java's 2D drawing tools.
- 11-14-2012, 10:55 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
It doesn't have to be fancy at all so I will go with whatever is easiest. So I will display the random words in a textbox but how will I compare those words to the words typed in the textarea?
- 11-14-2012, 11:03 PM #6
Re: typing application
You can both read and set the value of a textField/textArea. So, set your random words in one box, let the user type stuff in another, use an action listener to know when the user has either typed a letter or finished a word, and then just look at both fields and compare them!
- 11-15-2012, 06:08 PM #7
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
ok so i created an array with 10 words. i added a start button so when thats pressed the words appear in the textbox. i also added a next button so i could check all the words were displaying (i will delete this later). I have never used an action listener before so i am not sure how to compare the words.
also how can i move onto the next word in the text box when the person is finished typing the word in the textarea?
maybe change the word when they press the spacebar or something?Last edited by beginner123; 11-15-2012 at 07:20 PM.
- 11-15-2012, 07:31 PM #8
Re: typing application
The action listener does not compare the words, rather, it's what would trigger the words to be compared based on a user action, such as clicking a button. When the action listener is triggered, you tell it to execute any code you like - in your case a method for comparing the contents of the fields.
Sure! Again, this can be done with an action listener. If you 'listen' to every key press, you can look for a space character or whatever you like, and then make an action happen as a result. See this:How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)also how can i move onto the next word in the text box when the person is finished typing the word in the textarea?
maybe change the word when they press the spacebar or something?
- 11-15-2012, 09:22 PM #9
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
ok so i understand action listener now but how do i compare the words?
- 11-15-2012, 10:15 PM #10
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Re: typing application
Cross posted at how do you compare words?
- 11-16-2012, 04:23 AM #11
Re: typing application
.equals() or .compareTo() ?
- 11-16-2012, 09:04 PM #12
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
not really sure how to do that.
i tried this in the jTextArea1KeyReleased event:
but it just changes to the next word afterJava Code:if (Words.equals(Words)) { generateNextWord(); }
- 11-16-2012, 10:02 PM #13
Re: typing application
Ok, so ahm....
First off, what is Words? Also, you are comparing it to itself, so wouldn't it always be the same?
Look at this:
If you run that method, you'll see every case I demonstrated holds true. I showed you both equals and comparison with both case sensitive and insensitive comparisons.Java Code:public void wordTests(){ String alpha = "Hello"; String beta = "Goodbye"; assert alpha.equals(beta) == false; assert alpha.compareTo(beta) > 0; assert beta.compareTo(alpha) < 0; beta = "hello"; assert alpha.equals(beta) == false; assert alpha.equalsIgnoreCase(beta) == true; assert alpha.compareToIgnoreCase(beta) == 0; }Last edited by quad64bit; 11-16-2012 at 10:02 PM. Reason: typos
- 11-16-2012, 10:20 PM #14
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
yes I knew what I was doing was wrong but I only just starting learning java.
Here is my code for the array:
Words is the name of the array. So what do I need to compare this to?Java Code:Random r = new Random(); public int randomNumber; public String[] Words = new String[10]; public int WordCounter=0; private void fillLists() { Words[0] = "great"; Words[1] = "different"; Words[2] = "point"; Words[3] = "mountain"; Words[4] = "home"; Words[5] = "jumped"; Words[6] = "picture"; Words[7] = "mobile"; Words[8] = "fox"; Words[9] = "dog"; }
- 11-17-2012, 04:22 PM #15
Re: typing application
You can't just compare the whole array, you have to compare individual elements in the array. Also, please conform to java coding standards and only use capital letters for the beginnings of class names, not variable names.
If you wanted to find out if a word (entered by the user) was in a list, you need to do something like this:
Does that pseudocode help?Java Code:Loop through the array for the array index in question does the user's word equal the item in question? if so, the list contains the user word if not, loop again to try the next word end Loop If the item was not found in the loop, then it is not in the array.
- 11-17-2012, 06:54 PM #16
Member
- Join Date
- Nov 2012
- Posts
- 10
- Rep Power
- 0
Re: typing application
yes thats help a bit. So I need another variable for the words entered by the user?
- 11-18-2012, 01:08 PM #17
Similar Threads
-
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 -
Need to end program by typing quit and not -1!!! I have pasted my code for assistance
By sarchie109 in forum New To JavaReplies: 7Last Post: 11-23-2009, 08:42 AM -
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