/*ch0703.java*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ch0703 implements ActionListener    //实现动作事件监听接口
{ public ch0703()
    { JFrame f=new JFrame("发出声音");
      Container c=f.getContentPane();
      c.setLayout(new GridLayout(2,1));
      c.setFont(new Font("宋体",Font.PLAIN,16));
      JPanel p1=new JPanel();
      c.add("Center",p1);
      JButton btn=new JButton("按钮");
      p1.add(btn);
      btn.addActionListener(this);              //注册事件源的动作监听者
      JPanel p2=new JPanel();                   //创建面板p2
      c.add(p2);
      p2.setBackground(Color.yellow);
      p2.add(new JLabel("按一下按钮可听到响声！",JLabel.CENTER));
      f.setSize(200,100);
      f.show();
    }
  public void actionPerformed(ActionEvent e)
  { Toolkit.getDefaultToolkit().beep();         //动作事件发生时要作出的反应
  }
  public static void main(String args[])
  { new ch0703();
  }
}
