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

    Default 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

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default 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!

  3. #3
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default 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

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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.

  5. #5
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default 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?

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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!

  7. #7
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default 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.

  8. #8
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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.

    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?
    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)

  9. #9
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default Re: typing application

    ok so i understand action listener now but how do i compare the words?

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

    Default Re: typing application

    Cross posted at how do you compare words?

  11. #11
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: typing application

    .equals() or .compareTo() ?

  12. #12
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default Re: typing application

    not really sure how to do that.
    i tried this in the jTextArea1KeyReleased event:

    Java Code:
    if (Words.equals(Words))
            {
                generateNextWord();
            
            }
    but it just changes to the next word after

  13. #13
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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:

    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;
    }
    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.
    Last edited by quad64bit; 11-16-2012 at 10:02 PM. Reason: typos

  14. #14
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default 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:
    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";
        }
    Words is the name of the array. So what do I need to compare this to?

  15. #15
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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:
    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.
    Does that pseudocode help?

  16. #16
    beginner123 is offline Member
    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Default Re: typing application

    yes thats help a bit. So I need another variable for the words entered by the user?

  17. #17
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: typing application

    It doesn't have to be a declared variable, it could just be the contents of the text field
    Java Code:
    boolean sameWord = words[i].compareToIgnoreCase(someTextField.getText());

Similar Threads

  1. Typing into terminal
    By keo in forum New To Java
    Replies: 1
    Last Post: 03-15-2011, 09:09 AM
  2. Replies: 5
    Last Post: 10-30-2010, 06:56 PM
  3. 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
  4. Replies: 7
    Last Post: 11-23-2009, 08:42 AM
  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
  •