Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to use Backspace to remove a character from a String.
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mike200015




PostPosted: Fri Apr 20, 2007 6:49 pm   Post subject: How to use Backspace to remove a character from a String.

I have a text area with a document listener (below). When a user types into it, the input is saved into the string userInput, and the text is then removed from the text area so it is not displayed (using invokeLater). I need the Backspace key to do what it is supposed to do, remove the last character from the userInput string, but I don't know how to do that.

Please help,
Thanks
code:

typedArea.getDocument().addDocumentListener(new DocumentListener() {
      Document doc = (Document)typedArea.getDocument();
      public void insertUpdate(DocumentEvent e) {
        try {
          userInput += typedArea.getText(doc.getLength()-1, 1);
          System.out.println(userInput);
          Runnable clearText = new Runnable() {
            public void run() {
              typedArea.setText("");
            }
          };
          SwingUtilities.invokeLater(clearText);
        }
        catch(Exception ex) {
        }
 
      }
      public void removeUpdate(DocumentEvent e) {
      }
      public void changedUpdate(DocumentEvent e) {
      }     
    });
  }
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: