本文整理匯總了Java中java.awt.AWTEvent.getSource方法的典型用法代碼示例。如果您正苦於以下問題:Java AWTEvent.getSource方法的具體用法?Java AWTEvent.getSource怎麽用?Java AWTEvent.getSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.AWTEvent
的用法示例。
在下文中一共展示了AWTEvent.getSource方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: eventDispatched
import java.awt.AWTEvent; //導入方法依賴的package包/類
@Override
public void eventDispatched(AWTEvent event) {
if (event.getSource() == this) {
return;
}
if (event instanceof KeyEvent) {
if (event.getID() == KeyEvent.KEY_PRESSED) {
if( !changeSelection( (KeyEvent)event ) ) {
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
hideCurrentPopup();
} else {
((KeyEvent)event).consume();
}
}
}
}
示例2: eventDispatched
import java.awt.AWTEvent; //導入方法依賴的package包/類
/**
* Popup should be closed under some circumstances. Namely when mouse is
* pressed or released outside of popup or when key is pressed during the
* time popup is visible.
*/
public void eventDispatched(AWTEvent event) {
if (event.getSource() == this) {
return;
}
if (event instanceof MouseEvent) {
if (event.getID() == MouseEvent.MOUSE_RELEASED) {
long time = System.currentTimeMillis();
// check if button was just slowly clicked
if (time - invocationTime > 500) {
if (!onSwitcherTable((MouseEvent) event)) {
// Don't take any chances
hideCurrentPopup();
}
}
} else if (event.getID() == MouseEvent.MOUSE_PRESSED) {
if (!onSwitcherTable((MouseEvent) event)) {
// Don't take any chances
if (event.getSource() != invokingComponent) {
// If it's the invoker, don't do anything - it will
// generate another call to invoke(), which will do the
// hiding - if we do it here, it will get shown again
// when the button processes the event
hideCurrentPopup();
}
}
}
} else if (event instanceof KeyEvent) {
if (event.getID() == KeyEvent.KEY_PRESSED) {
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
hideCurrentPopup();
}
}
}
示例3: eventDispatched
import java.awt.AWTEvent; //導入方法依賴的package包/類
@Override
public void eventDispatched(AWTEvent aWTEvent) {
if (aWTEvent instanceof MouseEvent) {
MouseEvent mv = (MouseEvent) aWTEvent;
if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) {
//#118828
if (!(aWTEvent.getSource() instanceof Component)) {
hide();
return;
}
Component comp = (Component) aWTEvent.getSource();
Container par1 = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
if (par1 == null) {
hide();
}
}
}
}
示例4: eventDispatched
import java.awt.AWTEvent; //導入方法依賴的package包/類
/**
* Receives all key events in the AWT and processes the ones that originated
* from the current window with the glass pane.
*
* @param event the AWTEvent that was fired
*/
@Override
public void eventDispatched(AWTEvent event)
{
Object source = event.getSource();
// discard the event if its source is not from the correct type
boolean sourceIsComponent = (event.getSource() instanceof Component);
if( (event instanceof KeyEvent) && sourceIsComponent )
{
// If the event originated from the window w/glass pane, consume the
// event
if( (SwingUtilities.windowForComponent((Component) source) == theWindow) )
{
((KeyEvent) event).consume();
}
}
}
示例5: dispatchNextGuiEvent
import java.awt.AWTEvent; //導入方法依賴的package包/類
/**
* Processes the next GUI event.
*/
public void dispatchNextGuiEvent() throws InterruptedException {
EventQueue queue = awtEventQueue;
if (queue == null) {
queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
awtEventQueue = queue;
}
AWTEvent event = queue.getNextEvent();
if (event instanceof ActiveEvent) {
((ActiveEvent)event).dispatch();
} else {
Object source = event.getSource();
if (source instanceof Component) {
Component comp = (Component)source;
comp.dispatchEvent(event);
} else if (source instanceof MenuComponent) {
((MenuComponent)source).dispatchEvent(event);
}
}
}
示例6: eventDispatched
import java.awt.AWTEvent; //導入方法依賴的package包/類
@Override
public void eventDispatched(AWTEvent ev) {
if (!(ev instanceof WindowEvent))
return;
if (ev.getID() == WindowEvent.WINDOW_DEACTIVATED) {
lastWindowDeactivated = System.currentTimeMillis();
lastWindowDeactivatedSource = new WeakReference<Object>(ev.getSource());
anyWindowIsActivated = false;
if( Utilities.isWindows() ) {
//#247585 - even listening to clipboard changes when the window isn't active
//may throw a MS Windows error as the 'clipboard copy' action doesn't have enough time to finish
systemClipboard.removeFlavorListener(this);
}
}
if (ev.getID() == WindowEvent.WINDOW_ACTIVATED) {
if( Utilities.isWindows() ) {
systemClipboard.addFlavorListener(this);
}
anyWindowIsActivated = true;
if (System.currentTimeMillis() - lastWindowDeactivated < 100 &&
ev.getSource() == lastWindowDeactivatedSource.get()) {
activateWindowHack (false);
}
if (log.isLoggable (Level.FINE)) {
log.log (Level.FINE, "window activated scheduling update"); // NOI18N
}
scheduleGetFromSystemClipboard(true);
}
}
示例7: dispatchEvent
import java.awt.AWTEvent; //導入方法依賴的package包/類
private static void dispatchEvent(EventQueue queue, AWTEvent evt) throws Exception {
if (queue == null) {
queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
}
Method m = EventQueue.class.getDeclaredMethod("dispatchEvent", new Class[] {AWTEvent.class});
m.setAccessible(true);
if (evt.getSource() instanceof JTextField) {
foo = System.currentTimeMillis();
}
m.invoke(queue, new Object[] {evt});
}
示例8: onClick
import java.awt.AWTEvent; //導入方法依賴的package包/類
private void onClick(AWTEvent event) {
Component component = (Component) event.getSource();
if (outsideOfTooltipWindow(component)) {
// hide the tooltip if event occurs outside of the tooltip
shutdown();
}
}
示例9: setVisible
import java.awt.AWTEvent; //導入方法依賴的package包/類
@Override
public void setVisible(boolean visible) {
boolean blockParent = (visible && modal);
owner.setEnabled(!blockParent);
owner.setFocusableWindowState(!blockParent);
super.setVisible(visible);
if (blockParent) {
owner.addWindowListener(parentWindowListener);
try {
if (SwingUtilities.isEventDispatchThread()) {
EventQueue theQueue = getToolkit().getSystemEventQueue();
while (isVisible()) {
AWTEvent event = theQueue.getNextEvent();
Object src = event.getSource();
if (event instanceof ActiveEvent) {
((ActiveEvent) event).dispatch();
} else if (src instanceof Component) {
((Component) src).dispatchEvent(event);
}
}
} else {
synchronized (getTreeLock()) {
while (isVisible()) {
try {
getTreeLock().wait();
} catch (InterruptedException e) {
break;
}
}
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
} else {
owner.removeWindowListener(parentWindowListener);
// added 2 lines
owner.setEnabled(true);
owner.setFocusableWindowState(true);
}
}
示例10: eventToSpinner
import java.awt.AWTEvent; //導入方法依賴的package包/類
private JSpinner eventToSpinner(AWTEvent e)
{
Object src = e.getSource();
while( (src instanceof Component) && !(src instanceof JSpinner) )
{
src = ((Component) src).getParent();
}
return (src instanceof JSpinner) ? (JSpinner) src : null;
}
示例11: dispatchEvent
import java.awt.AWTEvent; //導入方法依賴的package包/類
public boolean dispatchEvent(AWTEvent e) {
if (e.getID() == FocusEvent.FOCUS_GAINED) {
System.out.println(e);
Component src = (Component)e.getSource();
if (src == frame.b1 || src == frame.b2) {
throw new TestFailedException("wrong focus transfer on removal!");
}
}
return super.dispatchEvent(e);
}
示例12: dispatchEvent
import java.awt.AWTEvent; //導入方法依賴的package包/類
public void dispatchEvent( AWTEvent event )
{
Object src = event.getSource();
if( event instanceof ActiveEvent )
{
((ActiveEvent)event).dispatch();
}
else if( src instanceof Component )
{
((Component)src).dispatchEvent( event );
}
else if( src instanceof MenuComponent )
{
((MenuComponent)src).dispatchEvent( event );
}
}