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()); } } }





Reply With Quote