Question

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 ?

Was it helpful?

Solution

You could create your own class which has a static method showMessageDialogAndBeep() which calls JOptionPane.showMessageDialog and beeps before.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top