import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class Gui {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame JFrame = new JFrame("Gui界面");
JFrame.setLocation(500,500);
JFrame.setSize(300, 200);
//创建一个文本框
TextField textfiled = new TextField(30);
//把文本框存放在窗口JFrame的北部
JFrame.add(textfiled,BorderLayout.NORTH);
//创建一个按钮 Button
Button btn = new Button("点我试试");
JFrame.add(btn);
//给按钮一个点击事件 使用匿名内部类
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String info = textfiled.getText();
System.out.println("嘿嘿嘿"+ info);
JFrame.setTitle(info);
}
} );
JFrame.pack();//自己调节窗口大小
JFrame.setVisible(true);//显示界面
//关闭窗口
JFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}