import java.awt.*;
import java.awt.event.*;public class SelfButton{
      public static void main(String args[]){
               Frame f=new Frame();
                    f.setSize(400,300);
                    f.setLayout(new FlowLayout());
               TextField t=new TextField(20);
             Button b=new Button("Test");
                 f.add(b);
                 f.add(t);
                   f.setVisible(true);         ActionListener listener=new TestLis(t);
                 b.addActionListener(listener);
                 f.addWindowListener(new WindowAdapter(){
                  public void windowClosing(WindowEvent e){
                     System.exit(0);
                  }
                }
                );          }
      static class TestLis implements ActionListener{
          TextField t;
          public TestLis(TextField tx){
              t = tx;
          }
              public void actionPerformed(ActionEvent e){
                      System.out.println(t.getText());
                  }
          }
}试试先!:)