當前位置: 首頁>>代碼示例>>Java>>正文


Java AWTEvent類代碼示例

本文整理匯總了Java中java.awt.AWTEvent的典型用法代碼示例。如果您正苦於以下問題:Java AWTEvent類的具體用法?Java AWTEvent怎麽用?Java AWTEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AWTEvent類屬於java.awt包,在下文中一共展示了AWTEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processEvent

import java.awt.AWTEvent; //導入依賴的package包/類
@Override
protected void processEvent(AWTEvent evt) {
    int id = evt.getID();
    if (id != KeyEvent.KEY_TYPED) {
        super.processEvent(evt);
        return;
    }

    KeyEvent kevt = (KeyEvent) evt;
    char c = kevt.getKeyChar();

    // Digits, backspace, and delete are okay
    // Note that the minus sign is not allowed (neither is decimal)
    if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
        super.processEvent(evt);
        return;
    }

    Toolkit.getDefaultToolkit().beep();
    kevt.consume();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:DitherTest.java

示例2: eventDispatched

import java.awt.AWTEvent; //導入依賴的package包/類
public void eventDispatched(java.awt.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)) {
                removePopup();
                return;
            }
            
            Component comp = (Component)aWTEvent.getSource();
            Container par1 = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
            Container par2 = SwingUtilities.getAncestorNamed(SUB_POPUP_NAME, comp); //NOI18N
            // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp);
            // if (par == null && barpar == null) {
            if ( par1 == null && par2 == null ) {
                removePopup();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:HintsUI.java

示例3: dispatchEvent

import java.awt.AWTEvent; //導入依賴的package包/類
/**
 * Dispatches {@code AWTEvent} to component passed in constructor. If
 * {@code (getDispatchingModel & JemmyProperties.QUEUE_MODEL_MASK) == 0}
 * dispatched event directly, otherwise uses
 * {@code javax.swing.SwingUtilities.invokeAndWait(Runnable)}<BR>
 *
 * @param event AWTEvent instance to be dispatched.
 * @throws ComponentIsNotVisibleException
 * @throws ComponentIsNotFocusedException
 */
public void dispatchEvent(final AWTEvent event) {
    // run in dispatch thread
    String eventToString = queueTool.invokeSmoothly(
            new QueueTool.QueueAction<String>("event.toString()") {
        @Override
        public String launch() {
            return event.toString();
        }
    }
    );
    output.printLine("Dispatch event " + eventToString);
    output.printGolden("Dispatch event " + event.getClass().toString());
    Dispatcher<Void> disp = new Dispatcher<>(event);
    queueTool.invokeAndWait(disp);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:EventDispatcher.java

示例4: waitEvent

import java.awt.AWTEvent; //導入依賴的package包/類
private AWTEvent waitEvent(long eventMask, long waitTime, TestOut waiterOutput) {
    EventWaiter waiter = new EventWaiter(eventMask);
    waiter.setTimeouts(timeouts.cloneThis());
    waiter.setOutput(waiterOutput);
    waiter.getTimeouts().
            setTimeout("Waiter.WaitingTime",
                    waitTime);
    waiter.getTimeouts().
            setTimeout("Waiter.TimeDelta",
                    timeouts.getTimeout("EventTool.EventCheckingDelta"));
    try {
        return waiter.waitAction(null);
    } catch (InterruptedException e) {
        output.printStackTrace(e);
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:EventTool.java

示例5: eventDispatched

import java.awt.AWTEvent; //導入依賴的package包/類
public @Override void eventDispatched(java.awt.AWTEvent aWTEvent) {
    if (aWTEvent instanceof MouseEvent) {
        MouseEvent mv = (MouseEvent)aWTEvent;
        if (mv.getClickCount() > 0) {
            //#118828
            if (! (aWTEvent.getSource() instanceof Component)) {
                return;
            }
            Component comp = (Component)aWTEvent.getSource();
            Container par = SwingUtilities.getAncestorNamed("progresspopup", comp); //NOI18N
            Container barpar = SwingUtilities.getAncestorOfClass(StatusLineComponent.class, comp);
            if (par == null && barpar == null) {
                hidePopup();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:StatusLineComponent.java

示例6: show

import java.awt.AWTEvent; //導入依賴的package包/類
public void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel(master.getTextComponent());

    Window w = SwingUtilities.windowForComponent(master.getTextComponent());
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y - 1);  // slight visual adjustment
    contentWindow.setVisible(true);

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:TooltipWindow.java

示例7: doSelect

import java.awt.AWTEvent; //導入依賴的package包/類
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    pTable.getSelectionModel().addListSelectionListener( this );

    displayer.getModel().addComplexListDataListener( this );

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);

    popup = new JPopupMenu();
    popup.setBorderPainted( false );
    popup.setBorder( BorderFactory.createEmptyBorder() );
    popup.add( pTable );
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation( locationX, locationY );
    popup.setInvoker( invokingComponent );
    popup.addPopupMenuListener( this );
    popup.setVisible( true );
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ButtonPopupSwitcher.java

示例8: eventDispatched

import java.awt.AWTEvent; //導入依賴的package包/類
public void eventDispatched(java.awt.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)) {
                hidePopup();
                return;
            }
            
            Component comp = (Component)aWTEvent.getSource();
            Container par = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
            // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp);
            // if (par == null && barpar == null) {
            if ( par == null ) {
                hidePopup();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:PopupUtil.java

示例9: 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();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:ButtonPopupSwitcher.java

示例10: EventQueueDelegateFromMap

import java.awt.AWTEvent; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public EventQueueDelegateFromMap(Map<String, Map<String, Object>> objectMap) {
    Map<String, Object> methodMap = objectMap.get("afterDispatch");
    afterDispatchEventArgument = (AWTEvent[]) methodMap.get("event");
    afterDispatchHandleArgument = (Object[]) methodMap.get("handle");
    afterDispatchCallable = (Callable<Void>) methodMap.get("method");

    methodMap = objectMap.get("beforeDispatch");
    beforeDispatchEventArgument = (AWTEvent[]) methodMap.get("event");
    beforeDispatchCallable = (Callable<Object>) methodMap.get("method");

    methodMap = objectMap.get("getNextEvent");
    getNextEventEventQueueArgument =
        (EventQueue[]) methodMap.get("eventQueue");
    getNextEventCallable = (Callable<AWTEvent>) methodMap.get("method");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:SwingUtilities3.java

示例11: eventDispatched

import java.awt.AWTEvent; //導入依賴的package包/類
public void eventDispatched(AWTEvent e) {
    if (popup == null) return;
    
    // Not a mouse event
    if (!(e instanceof MouseEvent)) return;
    MouseEvent me = (MouseEvent)e;
    
    // Event not relevant
    if (isIgnoreEvent(me)) return;
    
    // Mouse moved over popup
    if (me.getID() == MouseEvent.MOUSE_MOVED && overPopup(me)) return;
    
    if (!overPopup(me)) {
        // Mouse event outside of popup
        hidePopup();
    } else if (isForwardEvent(me)) {
        // Mouse event on popup, to be forwarded to table
        Point popupPoint = popupLocation;
        hidePopup();
        forwardEvent(me, popupPoint);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:ProfilerTableHover.java

示例12: selectItem

import java.awt.AWTEvent; //導入依賴的package包/類
/**
 * Creates and shows the popup with given <code>items</code>. When user
 * selects an item <code>SwitcherTableItem.Activatable.activate()</code> is
 * called. So what exactly happens depends on the concrete
 * <code>SwitcherTableItem.Activatable</code> implementation.
 * Selection is made when user releases a <code>releaseKey</code> passed on
 * as a parameter. If user releases the <code>releaseKey</code> before a
 * specified time (<code>TIME_TO_SHOW</code>) expires the popup won't show
 * at all and switch to the last used document will be performed
 * immediately.
 *
 * A popup appears on <code>x</code>, <code>y</code> coordinates.
 */
public static void selectItem(SwitcherTableItem items[], int releaseKey,
        int triggerKey, boolean forward, boolean cancelOnFocusLost) {
    // reject multiple invocations
    if (invokerTimerRunning) {
        return;
    }
    KeyboardPopupSwitcher.items = items;
    KeyboardPopupSwitcher.releaseKey = releaseKey;
    KeyboardPopupSwitcher.triggerKey = triggerKey;
    KeyboardPopupSwitcher.cancelOnFocusLost = cancelOnFocusLost;
    invokerTimer = new Timer(TIME_TO_SHOW, new PopupInvoker(forward));
    invokerTimer.setRepeats(false);
    invokerTimer.start();
    invokerTimerRunning = true;
    awtListener = new AWTListener();
    Toolkit.getDefaultToolkit().addAWTEventListener(awtListener, AWTEvent.KEY_EVENT_MASK);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:KeyboardPopupSwitcher.java

示例13: 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();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:ButtonPopupSwitcher.java

示例14: run

import java.awt.AWTEvent; //導入依賴的package包/類
public void run()
{
  while( isModal() )
  {
    handleIdleTime();
    try
    {
      AWTEvent event = Toolkit.getDefaultToolkit().getSystemEventQueue().getNextEvent();
      dispatchEvent( event );
    }
    catch( Throwable e )
    {
      handleUncaughtException( e );
    }
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:17,代碼來源:ModalEventQueue.java

示例15: eventDispatched

import java.awt.AWTEvent; //導入依賴的package包/類
@Override
public void eventDispatched(AWTEvent e) {
	if (e instanceof MouseEvent) {
		MouseEvent me = (MouseEvent) e;
		if (!SwingUtilities.isDescendingFrom(me.getComponent(), target)) {
			return;
		}
		if (me.getID() == MouseEvent.MOUSE_RELEASED) {
			// stop when mouse released
			mouseOnScreenPoint = null;
			if (timer.isRunning()) {
				timer.stop();
			}
		} else if (me.getID() == MouseEvent.MOUSE_DRAGGED && me.getComponent() == target) {
			mouseOnScreenPoint = me.getLocationOnScreen();
		} else if (me.getID() == MouseEvent.MOUSE_PRESSED && me.getComponent() == target) {
			mouseOnScreenPoint = me.getLocationOnScreen();
			timer.start();
		}
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:22,代碼來源:PanningManager.java


注:本文中的java.awt.AWTEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。