java例程练习(TextField)

import java.awt.*;
import java.awt.event.*;
public class TestTFAction {
	public static void main(String[] args) {
		new TFFrame();
	}

}

class TFFrame extends Frame {
	TFFrame() {
		TextField tf = new TextField();
		add(tf);
		tf.addActionListener(new TFActionListener());
		tf.setEchoChar('*');
		pack();
		setVisible(true);
	}
}

class TFActionListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		TextField tf = (TextField) e.getSource();
		System.out.println(tf.getText());
		tf.setText("");
	}
}

posted on 2012-05-06 20:14  Yours风之恋  阅读(207)  评论(0编辑  收藏  举报