Swing 中的声音

 
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class Audio extends JFrame {
  5.   
  6.   public Audio() {
  7.     super("Auditory Popups");
  8.     setDefaultCloseOperation(EXIT_ON_CLOSE);
  9.     UIManager.put("AuditoryCues.playList",
  10.       UIManager.get("AuditoryCues.defaultCueList"));
  11.     UIManager.put("OptionPane.questionSound"
  12.       "sounds/OptionPaneError.wav");
  13.     JPanel contentPane = (JPanel)this.getContentPane();
  14.     JPanel center = new JPanel();
  15.     ButtonGroup buttonGroup = new ButtonGroup();
  16.     JRadioButton defaultAudio = new JRadioButton("Default"true);
  17.     center.add(defaultAudio);
  18.     buttonGroup.add(defaultAudio);
  19.     defaultAudio.addActionListener(new ActionListener() {
  20.       public void actionPerformed(ActionEvent e) {
  21.         UIManager.put("AuditoryCues.playList",
  22.           UIManager.get("AuditoryCues.defaultCueList"));
  23.       }
  24.     });
  25.     JRadioButton offAudio = new JRadioButton("Off"false);
  26.     center.add(offAudio);
  27.     buttonGroup.add(offAudio);
  28.     offAudio.addActionListener(new ActionListener() {
  29.       public void actionPerformed(ActionEvent e) {
  30.         UIManager.put("AuditoryCues.playList",
  31.           UIManager.get("AuditoryCues.noAuditoryCues"));
  32.       }
  33.     });
  34.     JRadioButton onAudio = new JRadioButton("On"false);
  35.     center.add(onAudio);
  36.     buttonGroup.add(onAudio);
  37.     onAudio.addActionListener(new ActionListener() {
  38.       public void actionPerformed(ActionEvent e) {
  39.         UIManager.put("AuditoryCues.playList",
  40.           UIManager.get("AuditoryCues.allAuditoryCues"));
  41.       }
  42.     });
  43.     contentPane.add(center,  BorderLayout.CENTER);
  44.     JButton confirmButton = new JButton("Confirmation Dialog");
  45.     contentPane.add(confirmButton, BorderLayout.SOUTH);
  46.     confirmButton.addActionListener(new ActionListener() {
  47.       public void actionPerformed(ActionEvent e) {
  48.         int result = JOptionPane.showConfirmDialog(Audio.this
  49.           "Confirm?");
  50.         if (result == JOptionPane.YES_OPTION) {
  51.           JOptionPane.showMessageDialog(Audio.this"Confirmed");
  52.         } else {
  53.           JOptionPane.showMessageDialog(Audio.this"Rejected");
  54.         }
  55.       }
  56.     });
  57.     JButton messageButton = new JButton("Message Dialog");
  58.     contentPane.add(messageButton, BorderLayout.NORTH);
  59.     messageButton.addActionListener(new ActionListener() {
  60.       public void actionPerformed(ActionEvent e) {
  61.         JOptionPane.showMessageDialog(Audio.this"The Message");
  62.       }
  63.     });
  64.     this.pack();
  65.     show();
  66.   }
  67.   public static void main(String args[]) {
  68.     new Audio();
  69.   }
  70. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值