Results 1 to 2 of 2

Thread: testing for backspaces?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    testing for backspaces?

    I have a little program that traps keystrokes. But when the person backspaces i get returns instead of the cursor being placed one space back thus letting the user correct mistakes. Any idea what would be the bet route to go? Shoud i trap for the BackSpace button too?

    Code:
       import javax.swing.*; 
       import java.awt.*; 
       import java.awt.event.*; 
    
       class CatchType extends KeyAdapter{
           public JTextArea jta;       
           public JTextField jtf; 
    
           public static void main(String[] agrs){
            new CatchType();    
             
        }
    
         public CatchType(){
             JFrame jf = new JFrame("Typing Test");
             jta = new JTextArea();
             jtf = new JTextField();
             jta.setFont(new Font("Informal Roman", Font.BOLD, 44)); 
             jta.setLineWrap(true); 
             jta.setBackground(Color.black);
             jta.setForeground(Color.red);
             Container c = jf.getContentPane();
             c.setLayout(new BorderLayout());
             c.add(jta, BorderLayout.CENTER);
             c.add(jtf, BorderLayout.SOUTH);
             jf.addWindowListener(new WindowMonitor());
             jtf.addKeyListener(new Keyboard()); 
             jf.setSize(450,300);
             jf.setVisible(true);  
         }      
                 
       
         class Keyboard extends KeyAdapter{
         
          public void keyPressed(KeyEvent ke){
           Character text = new Character(ke.getKeyChar());
           jta.append(text.toString()); 
         }
       }
     }

  2. #2

Posting Permissions

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



Click Here to Expand Forum to Full Width