日期:2014-05-20  浏览次数:20692 次

请大家指点,万分感激!
import   java.awt.*;  
import   java.awt.event.*;  
class   Text3   implements   ActionListener  
{  
public   void   main(String[]   args)  
{  
Frame   f=new   Frame( "my   java ");  
f.setSize(600,400);  
f.setLocation(100,100);  
f.setLayout(new   FlowLayout());  
TextField   text1=new   TextField(10);  
TextField   text2=new   TextField(10);  
text1.setEchoChar( '* ');  
f.add(text1);  
f.add(text2);  
text1.addActionListener(this);  
f.show();  

}  

public   void   actionPerformed(ActionEvent   e)  
{  
if(e.getSource()==text1)  
{  
text2.setText(text1.getText());  
}  
}  

}  
请大家帮我看下这段代码出错的原因.意为在窗口上放两个文本框,后一个文本框显示前一个文本框的内容.  


------解决方案--------------------
每看出错误
------解决方案--------------------
JFrame是不能添加东西进去的
你这样改把
import java.awt.*;
import java.awt.event.*;
class Text3 implements ActionListener
{
public void main(String[] args)
{
JFrame f=new JFrame( "my java ");
f.setSize(600,400);
f.setLocation(100,100);
f.setLayout(new FlowLayout());
TextField text1=new TextField(10);
TextField text2=new TextField(10);
text1.setEchoChar( '* ');
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(2,1));
panel.add(text1);
panel.add(text2);
f.getContentPane().add(panel);
text1.addActionListener(this);
f.show();

}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==text1)
{
text2.setText(text1.getText());
}
}

} 这样就可以了