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


Java KeyEvent.getComponent方法代碼示例

本文整理匯總了Java中java.awt.event.KeyEvent.getComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.getComponent方法的具體用法?Java KeyEvent.getComponent怎麽用?Java KeyEvent.getComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.event.KeyEvent的用法示例。


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

示例1: keyTyped

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyTyped(KeyEvent evt) {
    if (!Character.isDigit(evt.getKeyChar()) && !Character.isISOControl(evt.getKeyChar())) {
        evt.consume();
        Component c = evt.getComponent();
        if (c != null) {
            c.getToolkit().beep();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:NumericKeyListener.java

示例2: showPopup

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void showPopup(KeyEvent keyEvent) {
    if (isContextMenuOn()) {
        return;
    }
    Component component = keyEvent.getComponent();
    if (component instanceof JMenuItem && (!(component instanceof JMenu) || ((JMenu) component).isSelected())) {
        return;
    }
    Point point = new Point(component.getX() + component.getWidth() / 2, component.getY() + component.getHeight() / 2);
    showPopup(component, point);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:12,代碼來源:ContextMenuHandler.java

示例3: valueChanged

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
private void valueChanged(KeyEvent e) {
	JTextField n = (JTextField) e.getComponent();
	if (subject.equals("address")) {
		controller.addressChanged(n.getText());
	} else if (subject.equals("name")) {
		controller.nameChanged(n.getText());
	} else if (subject.equals("salary")) {
		controller.salaryChanged(n.getText());
	}
}
 
開發者ID:amritbhat786,項目名稱:DocIT,代碼行數:11,代碼來源:ChangeListener.java

示例4: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public synchronized void keyPressed(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextPressed);
		c.setBackground(mBackgroundPressed);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:FlatterCheckBoxUI.java

示例5: keyReleased

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public synchronized void keyReleased(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextNormal);
		c.setBackground(mBackgroundNormal);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:FlatterCheckBoxUI.java

示例6: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyPressed(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextPressed);
		c.setBackground(mBackgroundPressed);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:FlatterButtonUI.java

示例7: keyReleased

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyReleased(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextNormal);
		c.setBackground(mBackgroundNormal);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:FlatterButtonUI.java

示例8: postProcessKeyEvent

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 * This method will be called by <code>dispatchKeyEvent</code>. It will
 * handle any unconsumed KeyEvents that map to an AWT
 * <code>MenuShortcut</code> by consuming the event and activating the
 * shortcut.
 *
 * @param e the KeyEvent to post-process
 * @return <code>true</code>
 * @see #dispatchKeyEvent
 * @see MenuShortcut
 */
public boolean postProcessKeyEvent(KeyEvent e) {
    if (!e.isConsumed()) {
        Component target = e.getComponent();
        Container p = (Container)
            (target instanceof Container ? target : target.getParent());
        if (p != null) {
            p.postProcessKeyEvent(e);
        }
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:DefaultKeyboardFocusManager.java

示例9: postProcessKeyEvent

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 * This method will be called by {@code dispatchKeyEvent}. It will
 * handle any unconsumed KeyEvents that map to an AWT
 * {@code MenuShortcut} by consuming the event and activating the
 * shortcut.
 *
 * @param e the KeyEvent to post-process
 * @return {@code true}
 * @see #dispatchKeyEvent
 * @see MenuShortcut
 */
public boolean postProcessKeyEvent(KeyEvent e) {
    if (!e.isConsumed()) {
        Component target = e.getComponent();
        Container p = (Container)
            (target instanceof Container ? target : target.getParent());
        if (p != null) {
            p.postProcessKeyEvent(e);
        }
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:DefaultKeyboardFocusManager.java

示例10: keyTyped

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyTyped(KeyEvent kT) {

char charackter = kT.getKeyChar();
String singleChar = Character.toString(charackter);

JTextField displayField = (JTextField) kT.getComponent();
String currValue = displayField.getText();
int caretPosition = displayField.getCaretPosition();

// --- Allow negative values ------------------
if (this.isFloatValue==true) {
	// --- Float values -----------------------
	if (singleChar.equals("-") && countCharsInString(currValue, charackter)<2) {
		return;
	}
} else {
	// --- Integer values ---------------------
	if (singleChar.equals("-") && caretPosition==0 && currValue.startsWith("-")==false) {
		return;
	}
}

if (this.isFloatValue==true) {
	// --- Float values -----------------------
	if (singleChar.equals(".") || singleChar.equals(",")) {
		if (currValue!=null) {
			if (currValue.contains(".") || currValue.contains("," )) {
				kT.consume();	
				return;
			}
		}
	} else  if (singleChar.equalsIgnoreCase("e")) {
		if (currValue!=null) {
			if (currValue.contains("e")) {
				kT.consume();	
				return;
			}	
		}
	} else  if (singleChar.matches( "[0-9]" ) == false) {
		kT.consume();	
		return;
	}
	
} else {
	// --- Integer or Long values ---------------------
	if ( singleChar.matches( "[0-9]" ) == false ) {
		kT.consume();	
		return;
	}
	
} // --- end if -------------------------------

}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:54,代碼來源:KeyAdapter4Numbers.java

示例11: dispatchKeyEvent

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 * Called by <code>dispatchEvent</code> if no other
 * KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or
 * if no other KeyEventDispatchers are registered. If the event has not
 * been consumed, its target is enabled, and the focus owner is not null,
 * this method dispatches the event to its target. This method will also
 * subsequently dispatch the event to all registered
 * KeyEventPostProcessors. After all this operations are finished,
 * the event is passed to peers for processing.
 * <p>
 * In all cases, this method returns <code>true</code>, since
 * DefaultKeyboardFocusManager is designed so that neither
 * <code>dispatchEvent</code>, nor the AWT event dispatcher, should take
 * further action on the event in any situation.
 *
 * @param e the KeyEvent to be dispatched
 * @return <code>true</code>
 * @see Component#dispatchEvent
 */
public boolean dispatchKeyEvent(KeyEvent e) {
    Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();

    if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
        if (!e.isConsumed()) {
            Component comp = e.getComponent();
            if (comp != null && comp.isEnabled()) {
                redispatchEvent(comp, e);
            }
        }
    }
    boolean stopPostProcessing = false;
    java.util.List<KeyEventPostProcessor> processors = getKeyEventPostProcessors();
    if (processors != null) {
        for (java.util.Iterator<KeyEventPostProcessor> iter = processors.iterator();
             !stopPostProcessing && iter.hasNext(); )
        {
            stopPostProcessing = iter.next().
                        postProcessKeyEvent(e);
        }
    }
    if (!stopPostProcessing) {
        postProcessKeyEvent(e);
    }

    // Allow the peer to process KeyEvent
    Component source = e.getComponent();
    ComponentPeer peer = source.getPeer();

    if (peer == null || peer instanceof LightweightPeer) {
        // if focus owner is lightweight then its native container
        // processes event
        Container target = source.getNativeContainer();
        if (target != null) {
            peer = target.getPeer();
        }
    }
    if (peer != null) {
        peer.handleEvent(e);
    }

    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:63,代碼來源:DefaultKeyboardFocusManager.java

示例12: dispatchKeyEvent

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 * Called by {@code dispatchEvent} if no other
 * KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or
 * if no other KeyEventDispatchers are registered. If the event has not
 * been consumed, its target is enabled, and the focus owner is not null,
 * this method dispatches the event to its target. This method will also
 * subsequently dispatch the event to all registered
 * KeyEventPostProcessors. After all this operations are finished,
 * the event is passed to peers for processing.
 * <p>
 * In all cases, this method returns {@code true}, since
 * DefaultKeyboardFocusManager is designed so that neither
 * {@code dispatchEvent}, nor the AWT event dispatcher, should take
 * further action on the event in any situation.
 *
 * @param e the KeyEvent to be dispatched
 * @return {@code true}
 * @see Component#dispatchEvent
 */
public boolean dispatchKeyEvent(KeyEvent e) {
    Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();

    if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
        if (!e.isConsumed()) {
            Component comp = e.getComponent();
            if (comp != null && comp.isEnabled()) {
                redispatchEvent(comp, e);
            }
        }
    }
    boolean stopPostProcessing = false;
    java.util.List<KeyEventPostProcessor> processors = getKeyEventPostProcessors();
    if (processors != null) {
        for (java.util.Iterator<KeyEventPostProcessor> iter = processors.iterator();
             !stopPostProcessing && iter.hasNext(); )
        {
            stopPostProcessing = iter.next().
                        postProcessKeyEvent(e);
        }
    }
    if (!stopPostProcessing) {
        postProcessKeyEvent(e);
    }

    // Allow the peer to process KeyEvent
    Component source = e.getComponent();
    ComponentPeer peer = source.peer;

    if (peer == null || peer instanceof LightweightPeer) {
        // if focus owner is lightweight then its native container
        // processes event
        Container target = source.getNativeContainer();
        if (target != null) {
            peer = target.peer;
        }
    }
    if (peer != null) {
        peer.handleEvent(e);
    }

    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:63,代碼來源:DefaultKeyboardFocusManager.java


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