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


Java KeyListener類代碼示例

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


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

示例1: processKeyEvent

import java.awt.event.KeyListener; //導入依賴的package包/類
@Override
protected void processKeyEvent(KeyEvent e) {
    KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
    if (enter.equals(ks)) {
        // Prevent JComponent.processKeyBindings() to be called (it is called from
        // JComponent.processKeyEvent() ), notify only registered key listeners
        int id = e.getID();
        for (KeyListener keyListener : getKeyListeners()) {
            switch(id) {
              case KeyEvent.KEY_TYPED:
                  keyListener.keyTyped(e);
                  break;
              case KeyEvent.KEY_PRESSED:
                  keyListener.keyPressed(e);
                  break;
              case KeyEvent.KEY_RELEASED:
                  keyListener.keyReleased(e);
                  break;
            }
        }
        if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) {
            synchronized(listeners) {
                List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners);
                for (CellEditorListener listener : list) {
                    listener.editingStopped(new ChangeEvent(this));
                }
            }
        }
        e.consume();
    } else {
        super.processKeyEvent(e);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:WatchesColumnModels.java

示例2: updateProviderOnSave

import java.awt.event.KeyListener; //導入依賴的package包/類
public KeyListener updateProviderOnSave() {
    return new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent ke) {
            if (isSave(ke)) {
                onSave();
            }
        }
    };
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:11,代碼來源:StyledEditor.java

示例3: listenToKeysListener

import java.awt.event.KeyListener; //導入依賴的package包/類
private KeyListener listenToKeysListener() {
    final KeyAdapter adapter = new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            String word = nameField.getText();
            if (word.length() < 18) {
                hotelNameTitle.setText(word);
                hotelNameTitle.repaint();
            } else {
                JOptionPane.showMessageDialog(modalFrame, "Hotel name maximum 18 charachter allowed!",
                        JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
            }
            super.keyTyped(e);
        }
    };
    return adapter;
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:18,代碼來源:HotelPropertiesWindow.java

示例4: validatorListener

import java.awt.event.KeyListener; //導入依賴的package包/類
private KeyListener validatorListener() {
	final KeyAdapter adapter = new KeyAdapter() {
		@Override
		public void keyTyped(KeyEvent e) {
			final EmailValidator validator = new EmailValidator();
			if(validator.validate(emailField.getText())) {
				markerLbl.setVisible(false);
				infoLabel.setText("");
				isValid = true;
			}
			else {
				markerLbl.setVisible(true);
				infoLabel.setText("Invalid email format!");
			}
		}
	};
	return adapter;
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:19,代碼來源:AddUserWindow.java

示例5: containsInGameComponents

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Checks if this {@code Canvas} contains any in game components.
 *
 * @return {@code true} if there is any in game components.
 */
public boolean containsInGameComponents() {
    KeyListener[] keyListeners = getKeyListeners();
    if (keyListeners.length > 0) {
        return true;
    }

    MouseListener[] mouseListeners = getMouseListeners();
    if (mouseListeners.length > 0) {
        return true;
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    if (mouseMotionListeners.length > 0) {
        return true;
    }

    return false;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:24,代碼來源:Canvas.java

示例6: removeInGameComponents

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Removes components that is only used when in game.
 */
public void removeInGameComponents() {
    // remove listeners, they will be added when launching the new game...
    KeyListener[] keyListeners = getKeyListeners();
    for (KeyListener keyListener : keyListeners) {
        removeKeyListener(keyListener);
    }

    MouseListener[] mouseListeners = getMouseListeners();
    for (MouseListener mouseListener : mouseListeners) {
        removeMouseListener(mouseListener);
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    for (MouseMotionListener mouseMotionListener : mouseMotionListeners) {
        removeMouseMotionListener(mouseMotionListener);
    }

    for (Component c : getComponents()) {
        removeFromCanvas(c);
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:25,代碼來源:Canvas.java

示例7: fireKeyPressed

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Description of the Method
 *
 * @param e Description of the Parameter
 */
public void fireKeyPressed(KeyEvent e) {
    for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) {
        KeyListener l = en.nextElement();
        l.keyPressed(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
    }
}
 
開發者ID:SarutaSan72,項目名稱:Yass,代碼行數:12,代碼來源:YassInput.java

示例8: fireKeyReleased

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Description of the Method
 *
 * @param e Description of the Parameter
 */
public void fireKeyReleased(KeyEvent e) {
    for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) {
        KeyListener l = en.nextElement();
        l.keyReleased(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
    }
}
 
開發者ID:SarutaSan72,項目名稱:Yass,代碼行數:12,代碼來源:YassInput.java

示例9: addListener

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Adds an event listener to the Panel.
 *
 * @param eventListener
 *        The event listener.
 *
 * @throws IllegalArgumentException
 *        If the event listener isn't supported by this function.
 */
public void addListener(final EventListener eventListener) {
    if (eventListener instanceof KeyListener) {
        this.addKeyListener((KeyListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseListener) {
        this.addMouseListener((MouseListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseMotionListener) {
        this.addMouseMotionListener((MouseMotionListener) eventListener);
        return;
    }

    throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
 
開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:28,代碼來源:Panel.java

示例10: removeListener

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Removes an event listener from the Panel.
 *
 * @param eventListener
 *        The event listener.
 *
 * @throws IllegalArgumentException
 *        If the event listener isn't supported by this function.
 */
public void removeListener(final EventListener eventListener) {
    if (eventListener instanceof KeyListener) {
        this.removeKeyListener((KeyListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseListener) {
        this.removeMouseListener((MouseListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseMotionListener) {
        this.removeMouseMotionListener((MouseMotionListener) eventListener);
        return;
    }

    throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
 
開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:28,代碼來源:Panel.java

示例11: removeListener

import java.awt.event.KeyListener; //導入依賴的package包/類
public void removeListener() {
    for (MouseListener ml : com.getMouseListeners()) {
        com.removeMouseListener(ml);
    }
    for (MouseMotionListener mml : com.getMouseMotionListeners()) {
        com.removeMouseMotionListener(mml);
    }
    for (KeyListener kl : com.getKeyListeners()) {
        com.removeKeyListener(kl);
    }
    reset();
    com.repaint();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:14,代碼來源:SelectionManager.java

示例12: addKeyListener

import java.awt.event.KeyListener; //導入依賴的package包/類
/**
 * Maps {@code Component.addKeyListener(KeyListener)} through queue
 */
public void addKeyListener(final KeyListener keyListener) {
    runMapping(new MapVoidAction("addKeyListener") {
        @Override
        public void map() {
            getSource().addKeyListener(keyListener);
        }
    });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ComponentOperator.java

示例13: addKeyListener

import java.awt.event.KeyListener; //導入依賴的package包/類
@Override
public synchronized void addKeyListener(KeyListener keyListener) {
    textArea.addKeyListener(keyListener); 
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:5,代碼來源:CodeEditor.java

示例14: addSearchKeyListener

import java.awt.event.KeyListener; //導入依賴的package包/類
public void addSearchKeyListener(KeyListener listener) {
    txtSearch.addKeyListener(listener);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:4,代碼來源:SearchField.java

示例15: setupSearch

import java.awt.event.KeyListener; //導入依賴的package包/類
private void setupSearch() {
    // Remove the default key listeners
    KeyListener[] keyListeners = getListeners(KeyListener.class);

    for (int i = 0; i < keyListeners.length; i++) {
        removeKeyListener(keyListeners[i]);
    }

    // Add new key listeners
    addKeyListener(
        new KeyAdapter() {
        @Override
            public void keyPressed(KeyEvent e) {
                int modifiers = e.getModifiers();
                int keyCode = e.getKeyCode();

                if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) {
                    return;
                }

                char c = e.getKeyChar();

                if (!Character.isISOControl(c) && (keyCode != KeyEvent.VK_SHIFT)) {
                    searchTextField.setText(String.valueOf(c));
                    displaySearchField();
                }
            }
        }
    );

    // Create a the "multi-event" listener for the text field. Instead of
    // adding separate instances of each needed listener, we're using a
    // class which implements them all. This approach is used in order
    // to avoid the creation of 4 instances which takes some time
    SearchFieldListener searchFieldListener = new SearchFieldListener();
    searchTextField.addKeyListener(searchFieldListener);
    searchTextField.addFocusListener(searchFieldListener);
    searchTextField.getDocument().addDocumentListener(searchFieldListener);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:ListView.java


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