当前位置: 首页>>代码示例>>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;未经允许,请勿转载。