I really appreciate your help, I had been trying if,else statements and none
of them worked. This had really been bugging me. Thanks so much!!


"MarkN" <M@N.com> wrote:
>
>Add a boolean
>at the top of your class:
>
>public class NameOnFrame extends JFrame
>{
> Private boolean whereTo = true;
>
>
>
>In your code, check the flag and set the fields based on it. Typical non-Java
>stuff.
>
>if(whereTo)
>{
> outputHere.setText(text.getText());
> text.setText("");
> whereto = false;
>}
>else
>{
> text.setText(outputHere.getText());
> outputHere.setText("");
> whereto = true;
>}
>
>
>
>
><java.@127.0.0.1> wrote:
>>
>>Thank you very much for your help. I tried that and it fixes 1 of the problems
>>I was having. The only other problem was that it still doesn't bring "a

>name"
>>back to the text field when the button is clicked for a 2nd time.
>>Thanks again
>>
>>
>><java.@127.0.0.1> wrote:
>>>
>>>Replace what is in your actionPerformed method with this:
>>>
>>>outputHere.setText(text.getText());
>>>text.setText("");
>>>
>>>"Mr. T" <java.@127.0.0.1> wrote:
>>>>
>>>>This program is supposed to move "a name"
>>>>from a text field to a text area when the change button is clicked, it

>>is
>>>>also supposed to move "a name" back and forth on subsequent button clicks.
>>>>I have gotten this far, but have been stuck now for a couple of days.

>this
>>>>code will take "a name" from the text field and place it in the text

area
>>>>(But it does not remove "a name" from the text field) I am new to Java

>>and
>>>>what I thought would work (using if,else statments) did not work. Any

>>Help
>>>>would be appreciated.
>>>>
>>>>Thanks
>>>>Code below
>>>>import java.awt.BorderLayout;
>>>>import javax.swing.JButton;
>>>>import javax.swing.JFrame;
>>>>import java.awt.event.ActionEvent;
>>>>import java.awt.event.ActionListener;
>>>>import javax.swing.JTextField;
>>>>import javax.swing.JPanel;
>>>>import javax.swing.JTextArea;
>>>>
>>>>
>>>>public class NameOnFrame extends JFrame
>>>>{
>>>> public NameOnFrame()
>>>> {
>>>>
>>>>
>>>>
>>>>
>>>> /* this creates a text field with my name in it
>>>> @param in the Text Field with my name in it
>>>> */
>>>> final JTextField text = new JTextField("a name");
>>>> text.setEditable(false);
>>>>
>>>>
>>>> JButton changeButton = new JButton("Change");
>>>>
>>>>
>>>>
>>>> final JTextArea outputHere = new JTextArea("");
>>>> outputHere.setEditable(false);
>>>>
>>>> //This is what happens when the button gets clicked
>>>> class changeButtonListener implements ActionListener
>>>> {
>>>> public void actionPerformed(ActionEvent event)
>>>> {
>>>> //This gets the name from the JTextField
>>>> String name = new String();
>>>> name = text.getText();
>>>>
>>>> //This prints the name inside the text area
>>>> outputHere.setText(name);
>>>>
>>>>
>>>>
>>>> }
>>>> }
>>>>
>>>> ActionListener listener = new changeButtonListener();
>>>> changeButton.addActionListener(listener);
>>>>
>>>>
>>>> getContentPane().add(text, BorderLayout.WEST);
>>>> getContentPane().add(changeButton, BorderLayout.EAST);
>>>> getContentPane().add(outputHere, BorderLayout.SOUTH);
>>>> }
>>>>}
>>>

>>

>