Swing/AuditoryCues のバックアップの現在との差分(No.2)
TITLE:AuditoryCuesでイベント音を設定する
AuditoryCuesでイベント音を設定する
Posted by terai at 2008-05-26- 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:
概要
UIManager
にAuditoryCues.playList
を設定して、ダイアログが開いた時の警告音などを鳴らします。
Screenshot
Advertisement
概要
UIManagerに"AuditoryCues.playList"を設定して、ダイアログが開いた時の警告音などを鳴らします。- &jnlp;
- &jar;
- &zip;
#screenshot
サンプルコード
#spanend
#spandel
Object[] optionPaneAuditoryCues = new Object[] {
#spanend
"OptionPane.errorSound", "OptionPane.informationSound",
"OptionPane.questionSound", "OptionPane.warningSound"
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
Object[] optionPaneAuditoryCues = {
#spanend
"OptionPane.errorSound",
"OptionPane.informationSound",
"OptionPane.questionSound",
"OptionPane.warningSound"
};
#spandel
//UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues"));
#spanend
#spandel
//UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.defaultCueList"));
#spanend
#spandel
//UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues"));
#spanend
#spanadd
// UIManager.put(
#spanend
#spanadd
// "AuditoryCues.playList",
#spanend
#spanadd
// UIManager.get("AuditoryCues.allAuditoryCues"));
#spanend
#spanadd
// UIManager.put(
#spanend
#spanadd
// "AuditoryCues.playList",
#spanend
#spanadd
// UIManager.get("AuditoryCues.defaultCueList"));
#spanend
#spanadd
// UIManager.put(
#spanend
#spanadd
// "AuditoryCues.playList",
#spanend
#spanadd
// UIManager.get("AuditoryCues.noAuditoryCues"));
#spanend
UIManager.put("AuditoryCues.playList", optionPaneAuditoryCues);
解説
上記のサンプルでは、デフォルトではすべて再生しないように設定されている聴覚フィードバックを、JOptionPaneでダイアログを開いた時には有効になるように変更しています。解説
上記のサンプルでは、デフォルトではすべて再生しないように設定されている聴覚フィードバックを、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
のイベント音の変更が可能UIManager.put("OptionPane.informationSound", "/example/notice2.wav");
参考リンク
- Swing コンポーネントの音声フィードバック
- Merlinの魔術: Swingのオーディオ
- "taitai studio" フリーWav素材集
- wavファイルを拝借しています。
参考リンク
- Swingコンポーネントの音声フィードバック - Java™ SE 1.4でのSwingの変更点および新機能
- Merlinの魔術: Swingのオーディオ
- "taitai studio" フリーWav素材集
- Beep音を鳴らす
- MIDIファイルの演奏
- Wavファイルの演奏