Solved

JAVA -- Textbox "KeyPress" EVENT on two textboxes

Posted on 2009-07-16
1
587 Views
Last Modified: 2012-05-07
I have two textboxes (TextBox1 & TextBox2)

Convert below C# code into JAVA
so I can use this one "TextBox_KeyPress"
EVENT on both textboxes.
------------------------------------------------------------  
private void TextBox_KeyPress(
      System.Object sender, KeyPressEventArgs e)
    {
      if (Char.IsLetter(e.KeyChar) && Char.IsLower(e.KeyChar)
        || char.IsWhiteSpace(e.KeyChar))
      {
        ((TextBox)sender).AppendText(
          Char.ToUpper(e.KeyChar).ToString());
        e.Handled = true;
      }
    }
0
Comment
Question by:finance_teacher
1 Comment
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24870730
Try something like the following :
    private class TextBoxKeyPress extends KeyAdapter {
        public void keyPressed(KeyEvent e) {
            char c = e.getKeyChar();
 
            if ((Character.isLetter(c) && Character.isLowerCaseChar(c)) ||
                    Character.isWhiteSpaceChar(c)) {
                textBox.append("" + Character.toUpperCase(c));
            }
        }
    }   

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sites similar to codingbat to improve coding hanson skills 3 49
Java DateChooser? 3 36
couple of eclipse 5 36
Adding multiple JVM environments to RedHat 6 7 18
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question