• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:AuditoryCuesでイベント音を設定する
#navi(../)
RIGHT:Posted by [[terai]] at 2008-05-26
*AuditoryCuesでイベント音を設定する [#v95f25a7]
UIManagerに"AuditoryCues.playList"を設定して、ダイアログが開いた時の警告音などを鳴らします。
---
category: swing
folder: AuditoryCues
title: AuditoryCuesでイベント音を設定する
tags: [UIManager, AuditoryCues, Sound, JOptionPane]
author: aterai
pubdate: 2008-05-26T17:13:17+09:00
description: UIManagerにAuditoryCues.playListを設定して、ダイアログが開いた時の警告音などを鳴らします。
image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTHzQ8XbXI/AAAAAAAAARw/-TGnQ_tvnnM/s800/AuditoryCues.png
---
* 概要 [#summary]
`UIManager`に`AuditoryCues.playList`を設定して、ダイアログが開いた時の警告音などを鳴らします。

-&jnlp;
-&jar;
-&zip;
#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTHzQ8XbXI/AAAAAAAAARw/-TGnQ_tvnnM/s800/AuditoryCues.png)

#screenshot

**サンプルコード [#b4933fee]
#code{{
* サンプルコード [#sourcecode]
#code(link){{
Object[] optionPaneAuditoryCues = {
  "OptionPane.errorSound", "OptionPane.informationSound",
  "OptionPane.questionSound", "OptionPane.warningSound"
  "OptionPane.errorSound",
  "OptionPane.informationSound",
  "OptionPane.questionSound",
  "OptionPane.warningSound"
};
//UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues"));
//UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.defaultCueList"));
//UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues"));
// UIManager.put(
//     "AuditoryCues.playList",
//     UIManager.get("AuditoryCues.allAuditoryCues"));
// UIManager.put(
//    "AuditoryCues.playList",
//     UIManager.get("AuditoryCues.defaultCueList"));
// UIManager.put(
//     "AuditoryCues.playList",
//     UIManager.get("AuditoryCues.noAuditoryCues"));
UIManager.put("AuditoryCues.playList", optionPaneAuditoryCues);
}}

**解説 [#nb3f1b60]
上記のサンプルでは、デフォルトではすべて再生しないように設定されている聴覚フィードバックを、JOptionPaneでダイアログを開いた時には有効になるように変更しています。
* 解説 [#explanation]
上記のサンプルでは、デフォルトではすべて再生しないように設定されている聴覚フィードバックを、`JOptionPane`でダイアログを開いた場合のみ有効になるように変更しています。

-showMessageDialog1
--L&Fデフォルトの音が鳴る(L&Fにデフォルトの音が無い場合は鳴らない)
--Windows L&F では、「コントロールパネル」「サウンドとオーディオデバイスのプロパティ」で、プログラムイベントが設定されている場合は鳴る
- `showMessageDialog1`
-- `LookAndFeel`デフォルトの音が鳴る(`LookAndFeel`にデフォルトの音が無い場合は鳴らない)
-- `WindowsLookAndFeel`では、「コントロールパネル」「サウンドとオーディオデバイスのプロパティ」で、プログラムイベントが設定されている場合は音が鳴る
- `showMessageDialog2`
-- 別途用意した`wav`ファイルを再生する
-- `UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues"))`として、二重に鳴らないように制限

-showMessageDialog2
--wavファイルで音を鳴らす
--UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues"))として、二重に鳴らないようにしている

----
metalやmotif L&F では、以下のようにすることで、MessageDialogのイベント音を変更することも出来ます。
- `MetalLookAndFeel`や`MotifLookAndFeel`では以下のように`MessageDialog`のイベント音の変更が可能
#code{{
UIManager.put("OptionPane.informationSound", "/example/notice2.wav");
}}

**参考リンク [#t9700925]
-[http://java.sun.com/javase/ja/6/docs/ja/technotes/guides/swing/SwingChanges.html#Miscellaneous Swing コンポーネントの音声フィードバック]
-[http://www.ibm.com/developerworks/jp/java/library/j-mer0730/ Merlinの魔術: Swingのオーディオ]
-[http://www.taitaistudio.com/wav/ "taitai studio" フリーWav素材集]
--wavファイルを拝借しています。
-[[Beep音を鳴らす>Swing/Beep]]
-[[MIDIファイルの演奏>Swing/MidiSystem]]
-[[Wavファイルの演奏>Swing/Sound]]
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/technotes/guides/swing/1.4/SwingChanges.html#bug4290988 Swingコンポーネントの音声フィードバック - Java™ SE 1.4でのSwingの変更点および新機能]
- [https://www.ibm.com/developerworks/jp/java/library/j-mer0730/ Merlinの魔術: Swingのオーディオ]
- [http://www.taitaistudio.com/wav/ "taitai studio" フリーWav素材集]
- [[Beep音を鳴らす>Swing/Beep]]
- [[MIDIファイルの演奏>Swing/MidiSystem]]
- [[Wavファイルの演奏>Swing/Sound]]

**コメント [#k5553b1c]
* コメント [#comment]
#comment
#comment