Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Converting Lowercase  to Uppercase Character.

Posted on 2000-02-27
10
701 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 10 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

856 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