Whenever i show a JOptionPane in my Swing application i fire a beep before it like this :
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog( myFrame, "Message", "Title", JOptionPane.INFORMATION_MESSAGE );
Is there a way to apply the first line automatically to any JOptionPane in case i forgot to write it in code ?
你可以创建自己的类,它有一个静态方法showMessageDialogAndBeep()
,它调用JOptionPane.showMessageDialog
并发出蜂鸣声。
void showMessageDialog(Component pC, Object m, String t, int mT) { Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog( pC, m,t,mT); }
I agree with org.life.java and atamanroman. Additionally I can suggest you the following. Create AWTListener and register it using
Toolkit.getDefaultToolkit().addAWTEventListener(listener, eventMask)
I think that this listener will be called in many cases including dialog opening. So you just have to recognize the case and call beep()
. I did not try this but I believe it will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.