• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:AuditoryCuesでイベント音を設定する
#navi(../)
RIGHT:Posted by [[terai]] at 2008-05-26
*AuditoryCuesでイベント音を設定する [#v95f25a7]
Posted by [[terai]] at 2008-05-26

#contents

**概要 [#r477c4dc]
UIManagerに"AuditoryCues.playList"を設定して、ダイアログが開いた時の警告音などを鳴らします。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#b4933fee]
#code{{
Object[] optionPaneAuditoryCues = {
  "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", optionPaneAuditoryCues);
}}

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

-showMessageDialog1(左)
--L&Fデフォルトの音が鳴る(L&Fにデフォルトの音が無い場合は鳴らない)
--Windows L&F では、「コントロールパネル」「サウンドとオーディオデバイスのプロパティ」で、プログラムイベントが設定されている場合は鳴る

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

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

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

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