"aung myo hein" to "nieh oym gnua"
how to convert with CharAt GUI JTextField or JOptionPane

I honestly cant figure out what you want. Please be more elaborate

he wants to input "hello" in an jTextBox and have a jLabel show "olleh"

@OP: the functionality of that method has nothing to do with how it is used, it's the same for a command line app as for a GUI app. what have you done so far?

he wants to input "hello" in an jTextBox and have a jLabel show "olleh"

@OP: the functionality of that method has nothing to do with how it is used, it's the same for a command line app as for a GUI app. what have you done so far?

WoW! how did u figure that out???

WoW! how did u figure that out???

nyeh, Sarcasm gone wild 2011? :P

Soooo no one answered you....

If you create a text box and a jlabel or second text box you can create a key listener

textBox.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent arg0) {
//The code here will do be performed each time someone presses a key in the text box.
}
});

That should help to get you started

Full Answer 1 is:

create two textBox's
textBox1 and textBox2

create one button
btnClickMe

btnClickMe.addActionListener(new ActionListener() {
    public void  actionPerformed(ActionEvent arg0) {
        //This gets the text in textBox1 then uses the string buffer to reverse the letters
        //The toString method converts the string buffer then to a string.
        //Then I store that into a String variable named rev and set that as the text of textbox 2
        String rev = new StringBuffer(textBox1.getText()).reverse().toString();
        textBox2.setText(rev);
    }
});

Full Answer 2 is:

create two textBox's
textBox1 and textBox2

create one button
btnClickMe

btnClickMe.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        //read text in from textbox1 and save into string variable
        String normal = textBox1.getText();
        //create string variable for reversed string
        //I'm setting it to nothing initially
        String rev = "";
        //loop through the string and place each char into a new string
        //this loop will start at the end of the string which is its length minus 1
        //the minus one is because the index starts at 0
        // the i>=0 means the loop will stop after that condition is no longer met
        for (int i =normal.length()-1; i>=0; i--){
            //This takes whatever was in the string rev and adds on the character at the end of normal
            rev += normal.charAt(i);
        }
        //This sets the text in textbox 2 to the reversed string
        textBox2.setText(rev);
    }
});

Answer 1 is cleaner

Answer 2 is what teachers are looking for students to understand in a programming course.

I hope that you understand what was done in the examples.

Full Answer 1 is:

create two textBox's
textBox1 and textBox2

create one button
btnClickMe

btnClickMe.addActionListener(new ActionListener() {
    public void  actionPerformed(ActionEvent arg0) {
        //This gets the text in textBox1 then uses the string buffer to reverse the letters
        //The toString method converts the string buffer then to a string.
        //Then I store that into a String variable named rev and set that as the text of textbox 2
        String rev = new StringBuffer(textBox1.getText()).reverse().toString();
        textBox2.setText(rev);
    }
});

Full Answer 2 is:

create two textBox's
textBox1 and textBox2

create one button
btnClickMe

btnClickMe.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        //read text in from textbox1 and save into string variable
        String normal = textBox1.getText();
        //create string variable for reversed string
        //I'm setting it to nothing initially
        String rev = "";
        //loop through the string and place each char into a new string
        //this loop will start at the end of the string which is its length minus 1
        //the minus one is because the index starts at 0
        // the i>=0 means the loop will stop after that condition is no longer met
        for (int i =normal.length()-1; i>=0; i--){
            //This takes whatever was in the string rev and adds on the character at the end of normal
            rev += normal.charAt(i);
        }
        //This sets the text in textbox 2 to the reversed string
        textBox2.setText(rev);
    }
});

Answer 1 is cleaner

Answer 2 is what teachers are looking for students to understand in a programming course.

I hope that you understand what was done in the examples.

we did answer him, we just didn't do his homework for him.
btw, why did the second field had to be a JTextBox, why not just a JLabel?

Yeah it could be a JLabel or any other component that supports setting text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.