如何主函数取出TextField中的内容
在主函数中如何取出TestField中的内容?import java.awt.*;
import java.awt.event.*;
public class Demo1
{String str1="";
String str2="";
String str3="";
public Demo1(){
this.launch();
}
public void launch(){
Frame f=new Frame("Encrypt");
f.setLayout(null);
Label l1=new Label("文件");
Label l2=new Label("密钥K");
Label l3=new Label("密钥G");
TextField tf1=new TextField(20);
TextField tf2=new TextField(20);
TextField tf3=new TextField(20);
Button b1=new Button("加密");
Button b2=new Button("解密");
Button b3=new Button("取消");
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
f.setLayout(new GridLayout(4,1));
f.add(p1);
f.add(p2);
f.add(p3);
f.add(p4);
p1.setLayout(new BorderLayout());
p2.setLayout(new BorderLayout());
p3.setLayout(new BorderLayout());
p4.setLayout(new FlowLayout());
p1.add(l1,"West");
p1.add(tf1,"East");
p2.add(l2,"West");
p2.add(tf2,"East");
p3.add(l3,"West");
p3.add(tf3,"East");
p4.add(b1,"East");
p4.add(b2,"East");
p4.add(b3,"East");
f.setVisible(true);
f.pack();
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(1);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);}
});
tf1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
TextField tf=(TextField)e.getSource();
str1=tf.getText();
tf.setText("");}
});
tf2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
TextField tf=(TextField)e.getSource();
str2=tf.getText();
tf.setText("");}
});
tf3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
TextField tf=(TextField)e.getSource();
str3=tf.getText();
tf.setText("");}
});
}
}
主函数
public class Main{
public static void main(String[] args){
Demo1 d1=new Demo1();
System.out.println(d1.str1);
}
}
怎么在TestField中输入的字符没打印出啊?