本文整理汇总了Java中java.awt.Component.addKeyListener方法的典型用法代码示例。如果您正苦于以下问题:Java Component.addKeyListener方法的具体用法?Java Component.addKeyListener怎么用?Java Component.addKeyListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.addKeyListener方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EventBinding
import java.awt.Component; //导入方法依赖的package包/类
/**
* Creates a new Binding.
* @param c the JOGLUI canvas
* @param d the FengGUI Display
*/
public EventBinding(Component c, Display d)
{
display = d;
// makes FengGUI listen to tab keys
// http://answers.google.com/answers/threadview?id=126916
c.setFocusTraversalKeysEnabled(false);
c.addMouseListener(this);
c.addMouseMotionListener(this);
c.addMouseWheelListener(this);
c.addKeyListener(this);
}
示例2: setKeyListener
import java.awt.Component; //导入方法依赖的package包/类
public static Component setKeyListener(Component c, KeyListener kl) {
if(c.getKeyListeners().length > 0) {
for(KeyListener g : c.getKeyListeners()) {
c.removeKeyListener(g);
}
}
c.addKeyListener(kl);
return c;
}
示例3: subscribeActual
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected void subscribeActual(Observer<? super KeyEvent> observer) {
Component w = widget;
KeyEventConsumer aec = new KeyEventConsumer(observer, w);
observer.onSubscribe(aec);
w.addKeyListener(aec);
if (aec.get() == null) {
w.removeKeyListener(aec);
}
}
示例4: addDeleteListener
import java.awt.Component; //导入方法依赖的package包/类
private Component addDeleteListener(Component comp) {
// System.out.println("");
// System.out.println("comp="+comp);
// if (comp.getClass() == sun.swing.FilePane.class) return comp;
if (comp instanceof Container) {
// System.out.println(comp+"\n");
// comp.addMouseListener(new MouseAdapter(){
// public void mouseEntered(MouseEvent e){
// System.out.println("mouse entered: "+e);
// }
// });
// if(comp.getClass().getEnclosingClass()==sun.swing.FilePane.class){
// System.out.println("******adding keyListener to "+comp);
comp.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
// System.out.println("delete key typed from "+e.getSource());
deleteFile();
}
}
});
// }
Component[] components = ((Container) comp).getComponents();
for (Component component2 : components) {
Component child = addDeleteListener(component2);
if (child != null) {
return child;
}
}
}
return null;
}
示例5: addDeleteListener
import java.awt.Component; //导入方法依赖的package包/类
private Component addDeleteListener(Component comp) {
// System.out.println("");
// System.out.println("comp="+comp);
// if (comp.getClass() == sun.swing.FilePane.class) return comp;
if (comp instanceof Container) {
// System.out.println(comp+"\n");
// comp.addMouseListener(new MouseAdapter(){
// public void mouseEntered(MouseEvent e){
// System.out.println("mouse entered: "+e);
// }
// });
// if this is a known filepane class, then add a key listener for deleting log files.
// may need to remove this in future release of java and
//find a portable way to detect we are in the FilePane
// if(comp.getClass().getEnclosingClass()==sun.swing.FilePane.class) {
// System.out.println("******adding keyListener to "+comp);
comp.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
// System.out.println("delete key typed from "+e.getSource());
deleteFile();
}
}
});
// }
Component[] components = ((Container) comp).getComponents();
for (Component component : components) {
Component child = addDeleteListener(component);
if (child != null) {
return child;
}
}
}
return null;
}
示例6: addKeyListeners
import java.awt.Component; //导入方法依赖的package包/类
/**
* Adds a feature to the KeyListeners attribute of the FileChooserFixer object
*
* @param c The feature to be added to the KeyListeners attribute
*/
private void addKeyListeners(Container c) {
for (int i = 0; i < c.getComponentCount(); i++) {
Component d = c.getComponent(i);
if (d instanceof Container) {
addKeyListeners((Container) d);
}
d.addKeyListener(this);
}
}
示例7: createAndShowGUI
import java.awt.Component; //导入方法依赖的package包/类
private static void createAndShowGUI() {
f = new JFrame();
final Component component = new JTextField();
component.addKeyListener(new MyKeyListener());
f.add(component);
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setAlwaysOnTop(true);
f.setVisible(true);
}