import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Myself extends Frame { JButton Exit; public Myself() { super("myself"); setSize(250,300); this.setLocation(300, 240); this.setBackground(Color.green); this.setLayout(new FlowLayout()); this.add(new Label("name")); this.add(new TextField("哆啦",25)); this.add(new Label("Stud_Number")); this.add(new TextField("19903311098",25)); this.add(new Label("sex")); this.add(new TextField("woman",25)); this.add(new Label("political status")); this.add(new TextField("Legue member",25)); Exit=new JButton("EXIT"); this.add(Exit); this.addWindowListener(new WinClose()); this.setVisible(true); } public static void main(String[] args) { new Myself(); //实例化 } } class WinClose implements WindowListener { public void windowClosing(WindowEvent ev) { ev.getWindow().dispose(); } //关闭窗口方法 public void windowOpened(WindowEvent ev) {} public void windowClosed(WindowEvent ev) {} public void windowIconified(WindowEvent ev) {} public void windowDeiconified(WindowEvent ev) {} public void windowActivated(WindowEvent ev) {} public void windowDeactivated(WindowEvent ev) {} }