开发者

Dispatching AWT Event With No User Input

开发者 https://www.devze.com 2023-03-14 18:38 出处:网络
I need to dispatch an event in AWT in the constructor of a panel. I need to do this because the AWT-EventQueue开发者_JAVA百科 needs to aquire a ReentrantLock and release it when the user clicks a butt

I need to dispatch an event in AWT in the constructor of a panel. I need to do this because the AWT-EventQueue开发者_JAVA百科 needs to aquire a ReentrantLock and release it when the user clicks a button.

How can I do this?


I've found an easy solution:

invokeLater()


What about:

AWTEvent e = ... 
this.dispatchEvent( e );
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent( e );
KeyboardFocusManager.getCurrentKeyboardFocusManager().processKeyEvent(this, (KeyEvent)e);
0

精彩评论

暂无评论...
验证码 换一张
取 消