문제

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 ?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top