Typing Tutor program

Hi,
Trying to write a typing tutor program. As you type a character it checks if it matches with the JTextArea. If it does match, it takes a snapshot of the text in the JTextField. If its wrong it sets the text back to the snapshot.
However, when I set the text back to the snapshot it displays the key typed aswell. How do I remove this character, so that only the snapshot is visible.
Heres the code:
//file:TTutor.java
//GUI typing tutor
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String.*;
class TTutor extends JFrame{
    String[] phrase = {"In a world full of people", "Only some want to fly", "Isn't that crazy?"};
     final JTextArea area = new JTextArea();
     final JTextField field = new JTextField(40);
    String failString= new String("");
    int caretp;
    int x, y;
    GridBagConstraints constraints = new GridBagConstraints();
    int i = 0;
    public TTutor(){
     super("TTutor v1.0");
     setSize(600, 300);
     setLocation(200, 200);
     setLayout(new GridBagLayout());
     area.setFont(new Font("Serif",Font.PLAIN, 18));
     area.setText(phrase[0]);
     area.setEditable(false);
     Container content = getContentPane();
     addGB(area, x=1, y=0);
     Image image = Toolkit.getDefaultToolkit().getImage("keyboard.jpg");
     addGB(new ImageComponent(image), x=1, y=1);
     addGB(field, x=1, y=2);
     setVisible(true);
     field.requestFocus();
     field.addKeyListener(new MyKeyListener());
     void addGB(Component component, int x, int y){
         constraints.gridx=x;
         constraints.gridy=y;
         add(component, constraints);
    public void update(KeyEvent ke){
     char c = ke.getKeyChar();
     String cs = Character.toString(c);
     char ac = area.getText().charAt(i);
      String as = String.valueOf(ac);
      if (as.equals(cs)){
       snapshot();
          i++;
       System.out.println("match");
      if (!as.equals(cs)){
       wrong();
      System.out.println("wrong");
    void snapshot(){
         failString = field.getText();
     caretp = field.getCaretPosition();
    void wrong(){
     /*Probelm is here:
       How do I get the textField to write the string minus the key typed
      field.setText("");
      field.setText(failString);
      field.setCaretPosition(caretp);     
    public static void main(String[] args){
     JFrame f = new TTutor();
     f.addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent we){System.exit(0);}
     f.setVisible(true);
public class MyKeyListener extends KeyAdapter{
    public void keyTyped(KeyEvent ke){
     update(ke);
     Regards ABourke.

Ideally I would like to get the TextField to work like the one in this demo:
http://www.quazart.org/cgi-bin/newtyping/demo.pl

Similar Messages

  • Touch typing tutor for OS 9?

    Hello there,
    Perhaps this isn't the right board for this question, but here goes anyway!
    I'm looking for a child-friendly, freeware touch-typing tutor program that I can install on 6 iBooks I want to use with my class... Does anyone know of such a piece of software?
    Thanks very much in advance...
    Steve

    I remember using this a long time ago. It was fun and child friendly; it has typing games.
    http://cgi.ebay.com/MAVIS-BEACON-TEACHES-TYPING-Version-16-PC-Mac-CD-NEW_W0QQite mZ130224339300QQihZ003QQcategoryZ41865QQssPageNameZWDVWQQrdZ1QQcmdZViewItem
    I don't remember if I used this version, but this one says it works with 9.1. Pretty close to being free...

  • Typing tutor software

    If this is in the wrong discussion group, I apologise.
    I'm looking for a typing tutor for my MacBook Air. I'm a hunt and peck type, and need to learn how to touch type.
    I write for a living, so it's vital that I master this skill.
    can anybody make a recommendation for either a free or paid for app. that may meet my needs?
    thanks in advance.

    The following one is free and has good reviews in the Mac App store. I have not used it myself. https://itunes.apple.com/us/app/typist/id415166115?mt=12

  • Arcade Typing Tutor

    I downloaded Arcade Typing Tutor 1.5 from the Apple Downloads web site onto two iMac machines and it will not run on either. Both are running OS 10.4.11. One is a PowerPC and the other an Intel machine. I double-click the application, it shows up briefly on the dock and then disappears.
    Anyone know what's up?

    Hi comod1, and a warm welcome to the forums!
    I don't have it to test unfortunately... on Dial-up here.
    Safe Boot from the HD, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, when that completes...
    Reboot.
    PS. Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.

  • Typing Closes Programs - Help!

    No idea what the **** is wrong with my MBP.
    It only started this issue today. Opened firefox and when i tried to type something in, it caused the program to crash. i thought it was an issue with firefox but the same happens with open.office and other programs. when i alt-tab to change program, it seems to force finder to crash as well.
    im a bit stumped. im using my girlfriends pc, with the 'i thought macs were better' smug look in her eye...

    Phil the Jock wrote:
    in the end i wiped the computer. its 5 yrs old and this has never been done yet. got lots of storage back on it!
    Glad you got it worked out.

  • Typing Training Program

    Does anyone knows how to write a java applet/application that can be used to train typing using keyboard (including words per second, errors of typing, etc)?
    Please share with me. Thanks.

    Here's a free typing test done using an Applet.
    http://www.scorpiosite69.freeserve.co.uk/typing.htm

  • SetLocation on a JLabel only sets it for a few milliseconds

    My main class extends JFrame, and I have two panels gameArea and commandArea. I set the Layout of the content pane to BorderLayout and placed JPanel gameArea in the Center and JPanel commandArea in the South. I didn't specify a layout for gameArea, although I believe it uses FlowLayout by default. I added my JLabel test to gameArea. I have a timer whose event fires every 10 milliseconds.
    I'm writing a typing tutor program for a class. The program is supposed to scroll a word down the screen, and if you type it before it hits the bottom you get a point. When you type a letter it uses HTML in the JLabel to increase the font size of the letters you've already typed.
    What I initially did was use Graphics.drawString to draw the word to the gameArea JPanel, but that produced a lot of flickering. What I'm doing now is using setLocation to move my JLabel (which contains the word) down the screen. The Timer event calls setLocation. I use the keyTyped event to grab the keystrokes.
    This looks much smoother, except the word still flickers at the top center of my window while it's moving down the page. If I don't type anything it looks fine, but once I start typing it starts flickering. If I click the Pause button, which stops the Timer, the JLabel moves up to the top center of my window and sits there.
    I've tried gameArea.setLayout(null) but then the JLabel doesn't appear on the screen at all. Any thoughts?

    You must set gameArea's layout to null, and set the size of your label because without layout the size will not be computed and you won't see the label...
    Hope this helped,
    Regards.

  • Calculating words per minute

    Hi, trying to write a typing tutor program.
    Having trouble calculating the words per minute.
    Does anyone know what Im doing wrong?
    import java.awt.*;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.Image;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JLabel;
    class TTutor extends JFrame{
        final JTextArea area= new JTextArea();
        final JTextField field = new JTextField(40);
        GridBagConstraints constraints = new GridBagConstraints();
        JLabel label = new JLabel();
        String[] phrase = { "In a world full of people",
                   "Only some want to fly",
                   "Isn't that crazy?"};
        int i = 0;
        int j = 0;
        int time = 0;
        double wps = 0;
        double wpm =0;
        int words= 0;
        int count = 0;
        public TTutor(){
         super("TTutor v1.0");
        void addGB (Component component, int x, int y){
         constraints.gridx = x;
         constraints.gridy = y;
         add(component, constraints);
        private void createAndShowGUI(){
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(600, 300);
         setLocation(200, 200);
         setLayout(new GridBagLayout());
         area.setFont(new Font("Serif", Font.PLAIN, 18));
         area.setText(phrase[0]);
         area.setEditable(false);
         addGB(area, 1, 0);
         field.addKeyListener(new KeyListener(){
              public void keyTyped(KeyEvent e){
                  update(e);
                  count++;
              public void keyPressed(KeyEvent e){
                  if (e.getKeyCode() == KeyEvent.VK_LEFT){
                   System.out.println("Left");
                   e.consume();
              public void keyReleased(KeyEvent e){}
         Image image = Toolkit.getDefaultToolkit().getImage("keyboard.jpg");
         addGB(new ImageComponent(image), 1, 1);
         addGB(field, 1, 2);
         Timer timer = new Timer();
         TimerTask task = new TimerTask(){
              public void run(){
                  time++;
                  String clock = String.valueOf(time);
                  System.out.println(clock);
                  System.out.println(count);
                  System.out.println(words);
                  System.out.println(wps);
                  System.out.println(wpm);
                  //calculate the words per minute - Anyone have any ideas?
                  try{
                  words = count/5; //1 word = 5 characters
                  wps = words/time;
                  wpm = wps * 60;
                  }catch(Exception e){System.out.println("error");}
                  String Wpm = String.valueOf(wpm);
                  label.setText("");
                  repaint();
         timer.scheduleAtFixedRate(task, 1000,1000);
         addGB(label, 2, 2);
         setVisible(true);
         field.requestFocus();
        public void update(KeyEvent ke){
         char c = ke.getKeyChar();
         System.out.println("" + (int)c);
         try{
         if (field.getText().equals(area.getText())){
             phrase[j] = phrase[j++];
             area.setText(phrase[j]);
             field.setText("");
             i=0;
    }catch(Exception e){System.out.println("error");}
         if (j == phrase.length){
         field.setText("");
         field.setEditable(false);
         area.setText("Finished");
         if (c == 8){
             ke.consume();
             System.out.println("Backspace consumed: "+ke.isConsumed());
             field.setText(area.getText().substring(0, i));
             return;
         if (i < area.getText().length()){
             char ac = area.getText().charAt(i);
             if (c == ac){
              System.out.println("match");
              i++;
             }else{
              System.out.println("no match");
              ke.consume();
         }else{
             ke.consume();
        public static void main (String[] args){
         java.awt.EventQueue.invokeLater(new Runnable(){
              public void run(){
                  new TTutor().createAndShowGUI();
    }Regards ABourke.

    Does anyone know what Im doing wrong?http://www.catb.org/~esr/faqs/smart-questions.html
    Now, before you take that the wrong way, please understand that the folks who answer questions here are volunteers. You're asking them to do a great deal of work just to figure out what problem you're having; not what the solution is, what the problem is. It's in your best interest to make your questions interesting and easy to answer. I can assure that few people will find copying, compiling, running, and playing detective just to figure out what trouble YOU are having is not likely to be easy to answer or interesting to anyone.
    Please consider this carefully, google "SSCCE", and rephrase your question. Thanks!
    ~

  • My imac keeps giving me a spinning color wheel and hangs up the machine for a few seconds and sometimes minutes. What could be the program and how can i get rid of it?

    My imac keeps giving me a spinning color wheel when i open and close applications and also when I am typing in programs. It happens and spins and then releases. I have done the following: Run virus software and found no problems, I have reinstalled the operating system, I have reloaded Iworks software, I have checked system prefrerences and still the problem continues. What could the problem be and how can I correct the problem?

    "the spinning wait cursor is displayed automatically by the window server when an application cannot handle all of the events it receives. If an application does not respond for about 2 to 4 seconds, the spinning wait cursor appears."
    read how to troubleshoot: http://www.macworld.com/article/151583/2010/05/spinningbeachballofdeath.html

  • Simple program not working

    Following an example from "C: The Programming Language" (Kernighan & Ritchie), I typed this program into XCode, using the Standard Tool Project under Command Line Utility:
    #include <stdio.h>
    /* count characters in input; 1st version */
    main()
    long nc;
    nc = 0;
    while (getchar() != EOF)
    ++nc;
    printf("%ld\n", nc);
    When I clicked Build & Go, I didn't get any errors, and the program ran fine. However, no matter what my input, I don't get an output. What's the problem with this program, and/or my computer?

    musicwind95 wrote:
    If I don't get a reply within a day or two here, I'm making a new thread with this.
    Once the A-team sees you've learned the cleverly hidden secret of how to say thanks around here, a new thread is like wearing a short skirt five minutes before closing.
    That said, your question is too interesting to pass up:
    When I click Build & Go, it tells me that the line "if (c == ' ' || c == '
    ' || c = '     ')" has an invalid lvalue in assignment.
    Your followers know c='t' was just a typo, but the Lval error it produced is very instructive.
    Typos that swap '=' for '==' often cause very tenacious bugs. In many cases the operators can be swapped without making the syntax invalid or causing a runtime error. Not too long ago I found code like this in a game program that had been online for over 12 years (ok, not a game played by half of all teenagers in North America, but literally 12+ yrs just the same):
    if (c = 2)
    activate = TRUE;
    else
    continue;
    The expression (c=2) not only assigns the value 2 to c, the value of the entire expression takes the value of the Lvar, which has become 2. When evaluating a boolean expression, everything but zero is TRUE, so the else branch is never reached. Most modern compilers will warn about a simple assignment (in the absence of any boolean operators) where a boolean is expected. But some of the compilers in use 12 yrs ago weren't that helpful.
    But (c==' ' || c=='
    ' || c='     ') is much more interesting! Boolean operators take precedence over assignments, so the boolean expressions are evaluated first, as if the larger expression were this:
    ( (c == ' ' || c == '
    ' || c) = '     ')
    When the inner expression is evaluated, the result is going to be either TRUE or FALSE; i.e. non-zero or zero (almost always TRUE in this case since c has just eaten a non-zero char). So now the expression becomes:
    1 = '     ' // <-- attempting to assign a constant (actually the integer 9) to a constant
    Whether the left side would evaluate to 1 or 0 is beside the point. Only a variable may be an Lval, hence the error.
    - Ray

  • Se38 - cannot create program

    Hi,
    I have another problem [with our company's SAP server].  I cannot create a program even though I am logged into the developer account.  I typed a program name "Z_KEVIN1" and clicked "create."  Here is the error box:
    Error in Object Editing [in title bar]
    System setting does not allow changes to be made to
    object PROG Z_KEVIN1
    Does anyone know how to resolve the above error?
    thanks!

    In SCC4, check your client settings for "Client Independent Object Changes". It should be something other than "No changes to Repository Objects" or "No Changes to Repository and Cross-client objects". The other two options allow you to create/change program objects.
    Please close the post if answered.
    Srinivas

  • An internal error has occurred! + Runtime error! Program C-

    I have Vista 64 SP2 all patches and Acrobat CS4 installed.Reader 9.4 was running without more then the normal troble with Adobe software. After installing Adobe Reade X it won't even start.
    The only  thing Reader X is doing is showing: An internal error has occurred!
    And: Runtime error! Program C… The program has requested the Runtime  to terminate in an unusual way. Please contact the application’s support  team for more information.
    I have enough of Adobes Beta Software released to me as a customer.  Never seen anything worse then your products. Flash as THE security hole  closely followed by Adobe reader. Okay that hole is closed now an  forever as I never will install anything from Adobe on my PC again. The  **** with downloading by Adobe DLM in firefox and such crap not to  mention.
    Welcome Foxit Reader!

    Hi,
    this Error can occur if you make use of JUNCTION in your filesystem. Sometimes those JUNCTIONS are made by your Operating System (e.g. windows anytime-upgrade and than changeing system language). But perhaps you manually changed program and data storage locations by using JUNCTION ( e.g. mklink or any other tool ).
    ONE SOLUTION which works for me was to install Adobe Reader manually by downloading the appropriate version at ftp://ftp.adobe.com/pub/adobe/reader/win . The startup with the desktop shortcut will not work.
    1. You should create a new Folder (e.g. TEST ) in the HOMEDRIVE ( normally C: ) root location which is not a JUNCTION .
    2. Open a command line ( press WinodwsKey+R than type "%COMSPEC%" without quotes and press OK Button)
    3. Use now the set command to change environment varibles temporarily Change APPDATA and USERPROFILE by typing
         SET APPDATA=C:\TEST
         SET USERPROFILE=C:\TEST
    4. Now start Adobe Reader from this command line by typing
         "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"
    Adobe Reader will open.
    5. You should go straight to Menu: Edit->Preferences->General
    Disable or deselect the "Enable Protected Mode at startup" at the bottom. Click OK. and exit Adobe Reader.
    6. Adobe settings are now written to C:\TEST
    copy all from C:\TEST to your original USERPROFILE dir
    Now you can use the desktop shortcut of Adobe Reader and it will also open pdf directly in your browser.

  • Unwanted programs in ALT+TAB window

    Hello everybody,
    I experienced a little problem days ago and it still present.
    I have Windows 8.1 64bit English version with no "wierd" programs installed: I have Microsoft Office, Hyper-V enabled and that's all.
    Every time I switch on my computer and I go to the Networks Pane (where you can enable/disable wireless and connect to a wireless network choosing from the list) or I search for apps using WIN button and typing the program name I see that these two programs
    (Search Pane and Network Pane I just used) appears in my ALT+TAB window and they don't disappear.
    I already cleaned the windows up: using ccleaner, hijackthis and using Disk Cleanup on my system partition. But all these actions didn't solve this annoying problem.
    Does someone experienced this?

    See the answer of dreik.
    That solved my problem!
    Navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer and
    delete setting named AltTabSettings.

  • PC has died so now I have to run my kids tutoring software on my mac.  Can anyone tell me what I need to do this?  The software disk isn't recognised by the mac.

    My PC has died and I now have to run my kids tutoring software on my mac but it's not compatible.  What do I need to do to get it to work on my macbook pro?

    lsm24 wrote:
    My PC has died and I now have to run my kids tutoring software on my mac but it's not compatible.  What do I need to do to get it to work on my macbook pro?
    If it's Windows 7 compatible you can use Apple's Bootcamp and create a partition on the drive (if there is room) and install Windows 7 there, then install the tutoring program while option booted into Windows. This is expensive and cumbersome for a simple program.
    https://www.apple.com/support/bootcamp/
    Another option would be to use virtual machine software like VMFusion (Apple sells), Parallels Desktop or the free (but a tiny bit harder to set up) VirtualBox from Oracle.
    Virtual machine programs run multiple operating systems under the parent OS, this case OS X, in a seperate window(s) or uses the full screen.
    Both solutions will require a FULL Windows 7 install disk, running about $300 for both 32/64 bit in the same box. Your machine will be tied up while the child is using it.
    Another option is to simply buy a another Windows 7 PC, or use another OS X compatible tutoring program.
    You can check over at CrossWeavers if the tutoring program can be run on OS X with a emulator you buy from them (less than Windows or a new box), not all Windows programs can, but you might be lucky and it runs fine with no issues.

  • Which group of programming languages to master?

    Which group of programming languages should I master to tackle a diverse set of problems? I would like for this list to be small as to not learn too many languages while not having a good grasp on them. The purpose of this is so I can approach any problem and pick the right tool for the job.
    Right now I'm thinking about C and Fortran for computational problems requiring speed (fortran because I'm a science student), Python for quick scripting and when development time is the most crucial factor, and Haskell for a functional middle ground. I appreciate any feedback.
    Last edited by Daedalus1 (2011-11-17 08:35:08)

    Calmatory wrote:Languages are merely tools to get things done. It is much more important to be able to think in an abstract manner to solve problems without creating more of them. Programming is the easy part, program design is the hard part.
    Yes, I know that. I guess the question I should have asked is which categories of languages are appropriate to which problems? Then I could pick one of each category and learn them.
    Basu wrote:
    I mostly second with whatever austin.rbn says but with some additions:
    1. You should learn C because it will make you learn how the machine actually works. Do not conflate C with C++, they are pretty different languages.
    2. You should learn a UNIX-y scripting language -- one of Perl/Python/Ruby for quick prototyping, string mangling, web dev, etc.
    3. You should learn an enterprise-y object oriented programming language such as C++, C# or Java
    4. You should learn a strongly typed functional programming language to better understand the mathematical basis of computer science like ML, OCaml or Haskell
    5. You should learn a Lisp dialect such as Scheme or Common Lisp (I would recommend the Racket implementation of Scheme).
    Let me know if you have any questions.
    Although pling may disagree with some of the reasons, these seem like sensible categories. What are some of the advantages of learning a Lisp language, and what domain would it be advantageous over other languages?
    bsilbaugh wrote:
    You may also want to ask yourself if you will ever need to run your codes in a distributed computing environment; e.g. a Linux cluster. If yes, then there is a high probability that you'll need to learn MPI. I know that most MPI implementations provide Fortran, C, and C++ API's, and there are also some Python wrappers out there as well (e.g. mpi4py).
    I should also point out that most Fortran, C, and C++ compilers support OpenMP out of the box. This means that a code that was initially written in Fortran, C, or C++ can be modified (usually rather easily) to take advantage of multi-core processors.
    As you might be aware, GPGPU computing is becoming more popular within the scientific community. Most of the GPGPU languages are minor extensions of the C language (and in some cases just additional C libraries). So, I suppose if you start out developing in C, then learning one of the GPGPU languages would seem like a natural extension of what you already know.
    (As others have alluded, you may want to view all of this as a never ending evolutionary process. That is, don't worry about finding some panacea to all your future programming needs today. Focus on learning the principles, keep and open mind, and be ready to adapt to an ever changing environment. Whatever the answers you get today, 10 years from now the answers will likely be very different.)
    Yes, I will eventually need to work with distributed computer systems and maybe GPU programming such as CUDA. For this purpose, where speed is critical, I would need to have C mastered. However I'm very used to the OOP methodology of Java and C++ and haven't been able to wrap my head around doing things otherwise. So as pling mentioned, I need to be able to first do procedural algorithms well and I think I need to learn C from the ground up. What I know of C, I've learned through C++. What is an introductory book that you would recommend to do this?
    pling wrote:Do what a pro and would do and code in the highly productive scripting language until you a performance hit, then write C code for that limited area. Rather than learning lots of languages badly, learn the fundamentals of procedural programming well - get books like Code Complete, Pragmatic Programming, Programming Perls, etc and work through them.
    Are C and python sufficient for general purpose programming? Are there any cases where it is difficult in getting the resultant amalgamated program to run smoothly? (just a wild guess)
    Last edited by Daedalus1 (2011-11-23 07:35:01)

Maybe you are looking for

  • User Exit required for restricting 1 vauation type in ME51N

    Hi Experts, I want to restrict that during the creation of PR i can only create the PR for materials for same valuation type. If there are 10 material then that should be of same valuation type. Please suggests.

  • Horizontal menu bar - increase the height and center the vertical treat position.

    I am using SpryMenuBarHorizontal.css and want to increase the height of a horizontal menu bar 20 28px and have the menu names move to be centered vertically, rather than be aligned at the top. Can anyone help me figure out how to do this?

  • Prevent using special characters in file and folder names?

    I've recently begun adding windows clients to my network. In doing so, I've found that on my file shares from OS X server, the windows clients are unable to see files and folders which have names containing special characters such as / ? < > \ : * |

  • Gr exchange rate

    Dear All, PO in USD which is a foreign currency. May I know what rate that during GR is using to calculate the amount in local currency? The day that do GR or the rate which updated in PO header delivery/invoice tab. Exchange rate fixed is NOT ticked

  • A540 Cursor/pointer problems

    Hi, on my A540 all-in-one cursor/pointer haphazardly jumps to the upper right corner of the screen and stays there blinking on a very high speed. Cannot do anything about it (cannot drag it back or control it) so I have to restart the machine using t