package Dome3; import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; public class Dome3 {
public static void main(String[] args) {
Frame f = new Frame("Dome3");
f.setBounds(500, 300, 300, 250); // 关闭按钮
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}); // 设置布局
f.setLayout(new FlowLayout()); // 添加控件 // 创建文本框
final TextField tf = new TextField(20);
// 创建文本域
final TextArea taArea = new TextArea(8, 30);
// 创建按钮
Button bt = new Button("确定"); // 为button创建点击事件
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
taArea.append(tf.getText() + "\r\n");
tf.requestFocus();
}
}); // 添加控件
f.add(tf);
f.add(bt);
f.add(taArea);
// 显示窗体
f.setVisible(true); }
}