本文整理汇总了Java中java.awt.event.KeyEvent.setSource方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.setSource方法的具体用法?Java KeyEvent.setSource怎么用?Java KeyEvent.setSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.setSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preDispatchKeyEvent
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private boolean preDispatchKeyEvent(KeyEvent ke) {
if (((AWTEvent) ke).isPosted) {
Component focusOwner = getFocusOwner();
ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
}
if (ke.getSource() == null) {
return true;
}
// Explicitly set the key event timestamp here (not in Component.dispatchEventImpl):
// - A key event is anyway passed to this method which starts its actual dispatching.
// - If a key event is put to the type ahead queue, its time stamp should not be registered
// until its dispatching actually starts (by this method).
EventQueue.setCurrentEventAndMostRecentTime(ke);
/**
* Fix for 4495473.
* This fix allows to correctly dispatch events when native
* event proxying mechanism is active.
* If it is active we should redispatch key events after
* we detected its correct target.
*/
if (KeyboardFocusManager.isProxyActive(ke)) {
Component source = (Component)ke.getSource();
Container target = source.getNativeContainer();
if (target != null) {
ComponentPeer peer = target.getPeer();
if (peer != null) {
peer.handleEvent(ke);
/**
* Fix for 4478780 - consume event after it was dispatched by peer.
*/
ke.consume();
}
}
return true;
}
java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers();
if (dispatchers != null) {
for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator();
iter.hasNext(); )
{
if (iter.next().
dispatchKeyEvent(ke))
{
return true;
}
}
}
return dispatchKeyEvent(ke);
}
示例2: preDispatchKeyEvent
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private boolean preDispatchKeyEvent(KeyEvent ke) {
if (((AWTEvent) ke).isPosted) {
Component focusOwner = getFocusOwner();
ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
}
if (ke.getSource() == null) {
return true;
}
// Explicitly set the key event timestamp here (not in Component.dispatchEventImpl):
// - A key event is anyway passed to this method which starts its actual dispatching.
// - If a key event is put to the type ahead queue, its time stamp should not be registered
// until its dispatching actually starts (by this method).
EventQueue.setCurrentEventAndMostRecentTime(ke);
/**
* Fix for 4495473.
* This fix allows to correctly dispatch events when native
* event proxying mechanism is active.
* If it is active we should redispatch key events after
* we detected its correct target.
*/
if (KeyboardFocusManager.isProxyActive(ke)) {
Component source = (Component)ke.getSource();
Container target = source.getNativeContainer();
if (target != null) {
ComponentPeer peer = target.peer;
if (peer != null) {
peer.handleEvent(ke);
/**
* Fix for 4478780 - consume event after it was dispatched by peer.
*/
ke.consume();
}
}
return true;
}
java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers();
if (dispatchers != null) {
for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator();
iter.hasNext(); )
{
if (iter.next().
dispatchKeyEvent(ke))
{
return true;
}
}
}
return dispatchKeyEvent(ke);
}