Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TextField(Urgent)

 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to get the value of one textbox to another text box when I click the button:
Here is my code:
import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.TextField;
import java.lang.*;
public class MyTest31 extends Applet implements ActionListener{
private Button b;
private TextField t1,t2;

public void init(){
setLayout(new FlowLayout());
t1 = new TextField(20);
t1.setText("Anuja");
add(t1);
t2 = new TextField(20);
add(t2);
b = new Button("Connect");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b)
t2.setText(t1);
}
}
What is wrong here?
Please let me know
Thanks
Angela
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela,
I think the problem might be this line:
t2.setText(t1);
Try changing it to this:
t2.setText(t1.getText());
and I think you will get the result you want.
Hope this helps.
Stephanie
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephanie;
Thanks a lot. U are right.

Angela
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic