Taking input from a JText field
<p>I'm trying to get the 'enlargeListener implements ActionListener' class to take the input from the shapeName JTextField and apply it into a for loop. The specifications being that if what is returned from the shapeName.getText() that is taken from the shapeName JTextfield matches what is specified in the loop (aka == "rectangle" or == "circle") it will implement the enlarge or shrink method. </p>

<p>The problem is I know it returns what is in the JTextField...but even if it meets the qualifications for the loop..the loop still fails and I can't figure out why. </p>

<p>For example..if I typed 'rectangle' into the first text box...it would return to the for loop under the 'enlargeListener implements' class as a string "rectangle". Yet when it is tested against == "rectangle" it still fails. I've combed through many, many documents to try to figure it out...but still I cannot. Any help would be appreciated :)</p>

<pre><code>import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import javax.swing.JPanel;  
import javax.swing.JTextField;  

public class TestShape extends JFrame  
{  
    Circle c;  
    Rectangle r;  
    JTextField shapeName;  
    JTextField areaText;  
    String input;  
    String area;  

    public TestShape()
    {

        JPanel jp = new JPanel();

        c = new Circle(65);
        r = new Rectangle(60,80);
        add(r);
        add(c);
        r.setBounds(10, 0, 300,300);
        c.setBounds(250, 0, 300, 300);


        getContentPane().add(jp);
        jp.setLayout(null);

        shapeName = new JTextField("  ");
        shapeName.setBounds(150, 200, 335, 22);
        jp.add(shapeName);
        add(jp);


        areaText = new JTextField();
        areaText.setBounds(150, 222, 335, 22);
        jp.add(areaText);
        add(jp);


        JButton enlarge = new JButton("Enlarge");
        enlarge.setBounds(150, 300, 80, 28);
        jp.add(enlarge);
        add(jp);
        enlarge.addActionListener(new enlargeListener());

        JButton shrink = new JButton("Shrink");
        shrink.setBounds(235, 300, 80, 28);
        jp.add(shrink);
        add(jp);    
        shrink.addActionListener(new shrinkListener()); 
    }


    public static void main(String[] args)
    {
        TestShape test = new TestShape();
        test.setVisible(true);
        test.setSize(500,500);
        test.setLocation(500,100);
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }




    class enlargeListener implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent arg0)
        {
            input = shapeName.getText().toString();

            if(input == "rectangle")
            {
            r.enlarge();
            //areaText.setText(r.getArea());
            }
            else if (input == "circle")
            {
                c.enlarge();
            }
            else
            {
                System.out.print("cannot do");
            }




        }


    }
    class shrinkListener implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e) 
        {
            if(shapeName.getText() == "rectangle")
            {
            r.shrink();
            }
            else
            {
            c.shrink();
            }

        }

    }   
}
</code></pre>
