当前位置: 首页>>代码示例>>Java>>正文


Java KeyEventDispatcher类代码示例

本文整理汇总了Java中java.awt.KeyEventDispatcher的典型用法代码示例。如果您正苦于以下问题:Java KeyEventDispatcher类的具体用法?Java KeyEventDispatcher怎么用?Java KeyEventDispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyEventDispatcher类属于java.awt包,在下文中一共展示了KeyEventDispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addKeyboardShortcutListener

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
private static void addKeyboardShortcutListener() {
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new KeyEventDispatcher() {
    private long lastPressTime = 0;

    @Override
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {

	if(System.currentTimeMillis() - lastPressTime > DELAY_KEY_PRESS) {
	    executeShortcut(keyEvent);
	    lastPressTime = System.currentTimeMillis();
	}
	
	return false; //continue to monitor other key events
    }

});
   }
 
开发者ID:MohitShridhar,项目名称:TASCA,代码行数:19,代码来源:MainInterface.java

示例2: makeHTMLButtonSpacable

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public static final void makeHTMLButtonSpacable(){
	if(HTML_BUTTONS) return;
	HTML_BUTTONS = true;
	
	KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
		@Override
		public boolean dispatchKeyEvent(KeyEvent ke) {
			if(ke.getID() == KeyEvent.KEY_RELEASED) return false;
			if(ke.getKeyCode() != KeyEvent.VK_ENTER && ke.getKeyCode() != KeyEvent.VK_SPACE) return false;
				
			if(ke.getSource() instanceof JButton){
				JButton jb = (JButton) ke.getSource();
				try {
					for(MouseListener ml: jb.getMouseListeners())
						ml.mouseReleased(new MouseEvent(jb, 1, 1, 1, -1, -1, 1, false, MouseEvent.BUTTON1));
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}

			return false;
		}
	});
}
 
开发者ID:fhissen,项目名称:CrococryptFile,代码行数:25,代码来源:SwingHacks.java

示例3: dialogInit

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
@Override
protected void dialogInit () {
	super.dialogInit();

	keyDispatcher = new KeyEventDispatcher() {

		@Override
		public boolean dispatchKeyEvent (KeyEvent e) {
			if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
				dispose();
				return true;
			}
			return false;
		}
	};
	KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
}
 
开发者ID:kotcrab,项目名称:arget,代码行数:18,代码来源:ESCClosableDialog.java

示例4: dbfViewerRecordPanel

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public dbfViewerRecordPanel(dbfViewer inParent, dbfTableModel indbfTableModel) throws Exception
{

   sp = new JScrollPane(this);
   parent = inParent;
   tableModel = indbfTableModel;
   setupDBFields();
class KeyDispatcher implements KeyEventDispatcher {

	 
	public boolean dispatchKeyEvent(KeyEvent e) {
		parent.fileChanged = true;
		return false;
	}
   	
   }
   KeyDispatcher keyDispatcher = new KeyDispatcher();
   KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);


}
 
开发者ID:sebkur,项目名称:xBaseJ,代码行数:22,代码来源:dbfViewer.java

示例5: keyboardEvent

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
/**
 * Evento que tiene en cuenta cuando presionas alguna tecla. Está desde que
 * se crea la instancia de Ventana principal en funcionamiento.
 *
 * El único funcionamiento por ahora es que al pulsar la tecla ESC se
 * deseleccionan las figuras seleccionadas en una VentanaInterna.
 */
public final void keyboardEvent() {
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                if (e.getKeyCode() == e.VK_ESCAPE) {
                    if (vi != null) {
                        vi.getLienzo().getvShapeSelected().clear();
                        repaint();
                        return true;
                    }
                }
            }
            return false;
        }
    });
}
 
开发者ID:oskyar,项目名称:Sistemas-Multimedia,代码行数:26,代码来源:VentanaPrincipal.java

示例6: initMap

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
private void initMap() {
	KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
	kfm.addKeyEventDispatcher(new KeyEventDispatcher() {

		@Override
		public boolean dispatchKeyEvent(KeyEvent e) {
			if (! AutoFindReferenceFrame.this.isActive()) return false;
			
			KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);
			
			if (!keyStroke.isOnKeyRelease() && keyStroke.getKeyCode() == KeyEvent.VK_P && keyStroke.getModifiers() == 0) {
				actionIgnore();
				return true;
			} else if (!keyStroke.isOnKeyRelease() && keyStroke.getKeyCode() == KeyEvent.VK_Q && keyStroke.getModifiers() == 0) {
				actionApply();
				return true;
			} else if (!keyStroke.isOnKeyRelease() && keyStroke.getKeyCode() == KeyEvent.VK_I && keyStroke.getModifiers() == 0) {
				actionApplyImDB();
				return true;
			}

			return false;
		}
	});
}
 
开发者ID:Mikescher,项目名称:jClipCorn,代码行数:26,代码来源:AutoFindReferenceFrame.java

示例7: Personalizar

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
private void Personalizar() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
    .addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
          teclaPressionada(e);
          return false;
        }
  });
}
 
开发者ID:iuryamicussi,项目名称:TrabalhoCrisParte2,代码行数:11,代码来源:Template.java

示例8: initListener

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public static void initListener() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            synchronized (KeyPressed.class) {
                switch (ke.getID()) {
                    case KeyEvent.KEY_PRESSED:{
                        if (ke.getKeyCode() == KeyEvent.VK_W) {
                            wPressed = false;
                        }
                        if(ke.getKeyCode()  == KeyEvent.VK_P){
                            pPressed = false;
                        }
                    }break;

                    case KeyEvent.KEY_RELEASED:{
                        if (ke.getKeyCode() == KeyEvent.VK_W) {
                            wPressed = !wPressed;
                        }
                        if(ke.getKeyCode()  == KeyEvent.VK_P){
                            pPressed = !pPressed;
                        }
                    }break;
                }
                return false;
            }
        }
    });
}
 
开发者ID:lucasbsimao,项目名称:autoNEAT,代码行数:31,代码来源:KeyPressed.java

示例9: SwingMain

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
/**
 * Creates new form SwingMain
 */
public SwingMain() {
    this.chip8Runner = new Thread(() -> {
        while (true) {
            try {
                if (running) {
                    if (pause == false || step) {
                        step = false;
                        chip8.cycle();
                        ((Chip8Model) jTable1.getModel()).update(chip8);
                    }
                    outputPanel.repaint();
                }
                sleep(1);
            } catch (InterruptedException ex) {
                Logger.getLogger(SwingMain.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    initComponents();
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            switch (e.getID()) {
                case KeyEvent.KEY_PRESSED:
                    Input.press(e.getKeyChar() + "");
                    break;
                case KeyEvent.KEY_RELEASED:
                    Input.unpress();
                    break;
                default:
                    break;
            }
            return false;
        }
    });
}
 
开发者ID:secondsun,项目名称:chip8,代码行数:41,代码来源:SwingMain.java

示例10: HotkeyManager

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public HotkeyManager(MainGui main) {
    this.main = main;
            
    if (Chatty.HOTKEY) {
        try {
            globalHotkeys = new GlobalHotkeySetter(new GlobalHotkeySetter.GlobalHotkeyListener() {

                @Override
                public void onHotkey(Object hotkeyId) {
                    onGlobalHotkey(hotkeyId);
                }
            });
            // If an error occured during initialization, then set to null
            // which means it's not going to be used.
            if (!globalHotkeys.isInitalized()) {
                globalHotkeyErrorWarning = globalHotkeys.getError();
                globalHotkeys = null;
            }
        } catch (NoClassDefFoundError ex) {
            LOGGER.warning("Failed to initialize hotkey setter [" + ex + "]");
            globalHotkeyErrorWarning = "Failed to initialize global hotkeys (jintellitype-xx.jar not found).";
            globalHotkeys = null;
        }
    }

    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            return applicationKeyTriggered(e);
        }
    });
}
 
开发者ID:chatty,项目名称:chatty,代码行数:35,代码来源:HotkeyManager.java

示例11: FlashBoulderBalkna

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public FlashBoulderBalkna() {
    Model.createrModel(configDir, new JavaxWawPlayerProvider());
    hack = this;
    initComponents();
    setLocales();
    reloadTrainings();

    f1 = new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F1 && e.getID() == KeyEvent.KEY_PRESSED) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        TrainingWithCycle tc = getSelectedTraining();
                        Training t = null;
                        Cycle c = null;
                        if (tc != null) {
                            t = tc.t;
                            c = tc.c;
                        }
                        SettingsDialogue d = new SettingsDialogue(t, c);
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(f1);
                        d.setVisible(true);
                        d.dispose();
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(f1);
                    }
                });

                return true;
            }
            return false;
        }
    };
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(f1);

}
 
开发者ID:judovana,项目名称:FlashBalknaSwing,代码行数:39,代码来源:FlashBoulderBalkna.java

示例12: HotkeyManager

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public HotkeyManager(MainGui main) {
    this.main = main;
            
    if (Chatty.HOTKEY) {
        try {
            globalHotkeys = new GlobalHotkeySetter(new GlobalHotkeySetter.GlobalHotkeyListener() {

                @Override
                public void onHotkey(Object hotkeyId) {
                    onGlobalHotkey(hotkeyId);
                }
            });
            // If an error occured during initialization, then set to null
            // which means it's not going to be used.
            if (!globalHotkeys.isInitalized()) {
                globalHotkeys = null;
            }
        } catch (NoClassDefFoundError ex) {
            LOGGER.warning("Failed to initialize hotkey setter [" + ex + "]");
            LOGGER.log(Logging.USERINFO, "Failed to initialize global "
                    + "hotkeys (if you don't use global hotkeys you can "
                    + "just ignore this).");
            globalHotkeys = null;
        }
    }

    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            return applicationKeyTriggered(e);
        }
    });
}
 
开发者ID:partouf,项目名称:Chatty-Twitch-Client,代码行数:36,代码来源:HotkeyManager.java

示例13: JSDOMBoxTestSuite

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
/**
 * Create the application
 */
public JSDOMBoxTestSuite() {
	initialize();
	createBrowserContent();
	
	// Resize Timer initialization
	resizeTimer = new Timer(200, new ActionListener() {
	    public void actionPerformed(ActionEvent evt) {
	        renderBrowserContent();
	        frmJsdomboxTestSuite.setVisible(true);
	        renderBrowserContent();
	    }
	});
	resizeTimer.setRepeats(false);
	
	// Keyboard Listener
	KeyboardFocusManager.getCurrentKeyboardFocusManager()
		.addKeyEventDispatcher(new KeyEventDispatcher() {
		
		@Override
		public boolean dispatchKeyEvent(KeyEvent e) {
			if (e.getID() != KeyEvent.KEY_PRESSED)
				return false;
			
			if (e.getKeyCode() == KeyEvent.VK_LEFT)
				jsdomboxButton.setSelected(true);
			
			if (e.getKeyCode() == KeyEvent.VK_RIGHT)
				cssboxButton.setSelected(true);
			
			return false;
		}
	});
}
 
开发者ID:rkocman,项目名称:JSDOMBox,代码行数:37,代码来源:JSDOMBoxTestSuite.java

示例14: initResources

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
private void initResources() {
desktop = Desktop.getDesktop();
kbfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
kbfm.addKeyEventDispatcher(new KeyEventDispatcher() {
    public boolean dispatchKeyEvent(KeyEvent e){
        return handleKeyEvents(e);
        }
    });
}
 
开发者ID:oscarryz,项目名称:GoDir,代码行数:10,代码来源:GoDir.java

示例15: waitForSequenceTyped

import java.awt.KeyEventDispatcher; //导入依赖的package包/类
public void waitForSequenceTyped(final int ... keys){
    final boolean [] keyTypeObject 	= new boolean[]{false};
    final KeyEventDispatcher dispatcher = new KeyEventDispatcher(){
	private volatile int keyArrayIndex = 0;
	@Override
	public synchronized boolean dispatchKeyEvent(KeyEvent evt) {//one at a time please...
	    if(evt.getID()==KeyEvent.KEY_RELEASED){
		if(evt.getKeyCode()==keys[keyArrayIndex]){
		    keyArrayIndex++;
		    if(keyArrayIndex>=keys.length){
			synchronized(keyTypeObject){
			    keyTypeObject[0]=true;
			    keyTypeObject.notifyAll();
			}//end sync(keyTypeObject)
			return false;
		    }//end if(>keys.length)
		}else keyArrayIndex=0;//!target key
	    }//end if(KEY_RELEASED)
	    return false;
	}};
	KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(dispatcher);
	synchronized(keyTypeObject){
	    while(!keyTypeObject[0]){
		try{keyTypeObject.wait();}
		catch(InterruptedException e){break;}
	    }//end while(!keyTypeObject)
	}//end sync(keyTypeObject)
	KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(dispatcher);
}
 
开发者ID:jtrfp,项目名称:terminal-recall,代码行数:30,代码来源:KeyStatusFactory.java


注:本文中的java.awt.KeyEventDispatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。