package 事件監聽;
import java.awt.*;
import java.awt.event.*;java
public class Frame2 extends Frame implements ActionListener{ private Button button1; public Frame2() { super("我的信息"); this.setSize(250,200);//設計組件的尺寸 this.setLocation(800,600);//設計組件顯示的位置 this.setBackground(Color.blue);//設計背景顏色 this.setLayout(new FlowLayout());//設計容器爲流佈局,居中 this.add(new Label("姓名")); this.add(new TextField("浩傑」,20)); this.add(new Label("性別")); this.add(new TextField("男",20)); this.add(new Label("民族")); this.add(new TextField("藏",20)); this.add(new Label("年齡")); this.add(new TextField("23",20)); button1=new Button("確認"); this.add(button1); button1.addActionListener(this); this.addWindowListener(new WinClose()); this.setVisible(true); } public void actionPerformed(ActionEvent ev) { if(ev.getSource()==button1) { System.out.print("welcome"); } } public static void main(String arg[]) { new Frame2(); } class WinClose implements WindowListener { public void windowClosing(WindowEvent ev) { System.exit(0); } public void windowOpened(WindowEvent ev) {} public void windowActivated(WindowEvent ev) {} public void windowDeactivated(WindowEvent ev) {} public void windowClose(WindowEvent ev) {} public void windowIconified(WindowEvent ev) {} public void windowDeiconified(WindowEvent ev) {} @Override public void windowClosed(WindowEvent arg0) { // TODO 自動生成的方法存根 } } }