?
Solved

Converting Lowercase  to Uppercase Character.

Posted on 2000-02-27
10
Medium Priority
?
731 Views
Last Modified: 2013-12-03
Hi!
In Java, is there any options to convert the lowercase character to uppercase character once typing in the textfied.  If yes, mind show me the command line.  Thanks.
Regards,
Huang Aun.
0
Comment
Question by:HuangAun
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 1

Expert Comment

by:technoman
ID: 2563619
you can use stringvar.toUpperCase()

where stringvar is a string variable.
0
 
LVL 3

Accepted Solution

by:
rjackman earned 30 total points
ID: 2563631
hi there try this out

import java.awt.*;
import java.awt.event.*;
public class TestString extends Frame implements ActionListener  
{
      private TextField tf;
      
      public TestString()
      {
            this.setSize(100,100);
            tf = new TextField(8);
            tf.addActionListener(this);
            this.add(BorderLayout.CENTER,tf);
                  
      }
      public void actionPerformed(ActionEvent e)
      {
            //enter the value & then press enter button will convert upper
            //case value to lower case
            String a = tf.getText();
            String b = tf.getText();
            int x = b.compareTo(a.toLowerCase());
            if(x == 0 )
            {
            b = a.toUpperCase();
                  tf.setText(b);
            }
            
      }
      public static void main(String args[])
      {
            TestString ts = new TestString();
            ts.setVisible(true);
      }
}
0
 
LVL 2

Expert Comment

by:muraliram
ID: 2563946
If you want to convert the text as you are typing try the following.

import java.awt.*;
import java.awt.event.*;

public class uppercase extends Frame implements TextListener  
{
TextField t;

public uppercase()
{
t = new TextField(20);
setLayout(new FlowLayout());
this.setSize(200,200);
add(t);
t.addTextListener(this);
this.setVisible(true);
}

public void textValueChanged(TextEvent e)
{
t.setText(t.getText().toUpperCase())

}
public static void main(String args[])
{
uppercase u = new uppercase();
}
}

This will work properly if you want to convert while typing itself.I think this is your requirement.

Good Luck
muraliram
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:jadrek85
ID: 2564221
Hi Muraliram,
As for as I know, there is no event called textValiueChanged. We can use the following line of code in text box keyRelease Event. Try this, this is working.


 void txtStTime_keyReleased(KeyEvent e) {
    txtStTime.setText(txtStTime.getText().toUpperCase()) ;
  }

Cheers,

Jadhav
0
 
LVL 2

Expert Comment

by:muraliram
ID: 2564367
Dear jadrek85,

Copy the above code and try it. There is an event called textValueChanged.
There is nothing wrong with that event.

muraliram
0
 
LVL 1

Expert Comment

by:jadrek85
ID: 2564514
Hi Muraliram,

You are right. I didn't observer that you are using awt component. But, the entered characters are padding left hand side of the text box and the text box area is blinking. I think you may need to validate and repaint the text box. Thanks for giving clarification. Keep it up.

Cheers,
Jadhav
0
 
LVL 2

Expert Comment

by:muraliram
ID: 2564738
Dear jadrek85,

Thanks. I have noticed the problem of blinking.

Bye
muraliram
0
 

Author Comment

by:HuangAun
ID: 2567505
The textField only can support for a single chracter and not a word.
Anyway, Rjackman suggestion work but need to do a little bit modification to support the string even lowercase or uppercase.  I accept Rjackman suggection but where can I do it.
0
 

Author Comment

by:HuangAun
ID: 2567512
Thanks.  it work's.
But need to modify a little bit to convert it even combination from lowercase and uppercase.
Thanks a lot.
0
 
LVL 3

Expert Comment

by:rjackman
ID: 2567673
hi HuangAun
thanx for appreciting my comment
in ur problem statement u have mentioned on for lowercase conversion to uppercase that's why i havenot considered the mixed case if u want can post the code for same
thanx again
---RickyJackman
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
The viewer will learn how to implement Singleton Design Pattern in Java.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

839 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