import java.awt.*;
import java.awt.event.*;
class Myframe extends Frame implements ActionListener
{TextField text1,text2;
Myframe(String s)
{super(s);
setLayout(new FlowLayout());
TextField text1=new TextField(10);
TextField text2=new TextField(10);
add(text1);
text1.addActionListener(this);
add(text2);
setBounds(20,30,300,200);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==text1)
text2.setText(text1.getText());}}
class Test
{public static void main(String args[]) {new Myframe("窗口");}
}怎么改text2这个文本框总是什么反应都没有,各位试试,哪里有错啊?
import java.awt.event.*;
class Myframe extends Frame implements ActionListener
{TextField text1,text2;
Myframe(String s)
{super(s);
setLayout(new FlowLayout());
TextField text1=new TextField(10);
TextField text2=new TextField(10);
add(text1);
text1.addActionListener(this);
add(text2);
setBounds(20,30,300,200);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==text1)
text2.setText(text1.getText());}}
class Test
{public static void main(String args[]) {new Myframe("窗口");}
}怎么改text2这个文本框总是什么反应都没有,各位试试,哪里有错啊?
class Myframe extends Frame implements ActionListener
{TextField text1=new TextField(10);
TextField text2=new TextField(10);
Myframe(String s)
.......
.......
为什么我在书上看到的例子这样是可以的:
class Myframe extends Frame implements ActionListener
{TextField text1=new TextField(10);
TextField text2=new TextField(10);
Myframe(String s)
{super(s);
text1=new TextField(10);
text2=new TextField(10);}}
却是可以的????