晕,这样的例子哪本java的教科书上都有的啊,去翻翻就查到了啊

解决方案 »

  1.   

    算了,帮你写一个吧:
    ===========================
    class MyFrame extends Frame implements ActionListener{
    Frame f;
    Label label;
    TextField text;
    MyFrame(String s){
    super(s);
    f = new Frame(s);
    setLayout(new BorderLayout());
    text = new TextField("11212123",30);
    label = new Label("Default");
    text.addActionListener(this);

    add(text,"North");
    add(label,"South");
    setSize(200,200);
    setVisible(true);
    addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}}); }

    /* (非 Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
    // TODO 自动生成方法存根
    if(e.getSource() == text){
    label.setText(text.getText());
    }
    }


    }public class temp { /**
     * 
     */
    public temp() {
    super();
    // TODO 自动生成构造函数存根
    }


    public final static void main(String[] args)  { Frame f = new MyFrame("我的窗口");
    f.pack();
    }

    }