Hey guys Im having trouble with my interface java program I have it all set up but im getting an error on my lowercase button and uppercase. is there a certaint type of formate this needs to be in for interface?

here is my code:

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
public class Week_ten_number_thirty_eight extends JFrame
{
    private Container contents;
    private JLabel inputLabel, resultLabel, result;
    private JTextField wordInput;
    private JButton Lowercase, Uppercase;

public Week_ten_number_thirty_eight()
{
    super("Lowercase or Uppercase?");
    contents = getContentPane();
    contents.setLayout(new FlowLayout());

    inputLabel = new JLabel("Enter a single word");//text field label
    wordInput = new JTextField(8);//text field is 8 characters wide

    //instantiate buttons
    Lowercase = new JButton("Lowercase");
    Uppercase = new JButton("Uppercase");

    resultLabel = new JLabel("Result");//label for result
    result = new JLabel ("???");//label to hold result

    //add components to the window
    contents.add(inputLabel);
    contents.add(resultLabel);
    contents.add(result);
    contents.add(wordInput);
    contents.add(Lowercase);
    contents.add(Uppercase);

    //instantiate our event handler
    ButtonHandler bh = new ButtonHandler();

    Lowercase.addActionListener(bh);
    Uppercase.addActionListener(bh);
    setSize(175,150);
    setVisible(true);
}
    //private inner class event handler
    private class ButtonHandler implements ActionListener
    {
        //implement actionPerformed method
        public void actionPerformed (ActionEvent ae)
        {
        if(ae.getSource() == Lowercase)
            {
          result.setText(wordInput.toLowercase());
            }
            else if (ae.getSource()==Uppercase)
            {
              result.setText(wordInput.toUppercase());
          }
        }   
    }

    public static void main(String[] args) 
    {
        Week_ten_number_thirty_eight out = new Week_ten_number_thirty_eight();
        out.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

the errors are coming up on line 59 and 63

thanks guys.

Recommended Answers

All 12 Replies

what does the error message say please post full message here

wordInput.getText().toXxx()

the error is cannot find symbol method toLowercase() and toUppercase.

tried mKorbel suggestion and nothing didnt work

Please post the FULL text of the error message that shows the source statement.

cannot find symbol method toLowercase()

What class is that method in? The compiler can not find a method with that name in the class you are using to call the method. Make sure you are using the correct method and/or the correct class reference.

its in a private class?

I was asking about the methods in the error message:

cannot find symbol method toLowercase() and toUppercase.

cannot find symbol
symbol  : method toUppercase()
location: class java.lang.String
                wordInput.getText().toUppercase();

cannot find symbol
symbol  : method toLowercase()
location: class java.lang.String
                wordInput.getText().toLowercase();

Java names are case sensitive. If you look at the API documentatiuon for the String class you will find the correct versions of those method names.

Alright! thanks I got just forgot that that the c in Uppercase and Lowercase was not capital. ok now the program can run but I am not getting the result in the result label?

thank you!

Is the code executing the way you want? Add some println statements to see where the code is executing and what values it is working with.

i got it just needed to add to it:

if(ae.getSource() == Lowercase)
            {
                wordInput.getText().toLowerCase();
                result.setText((new String(wordInput.getText())).toLowerCase());  
            }
            else if (ae.getSource()==Uppercase)
            {
                wordInput.getText().toUpperCase();
                result.setText((new String(wordInput.getText())).toUpperCase());
            }

Thanks Guys!

Lines 3 & 8 do nothing and could be removed.
Also the calls to new String(...) are not needed. The toXXXCase methods return a String.

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.