Solved

Converting Lowercase  to Uppercase Character.

Posted on 2000-02-27
10
688 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now