本文整理汇总了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
}
});
}
示例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;
}
});
}
示例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);
}
示例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);
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
}
});
}
示例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;
}
});
}
示例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);
}
});
}
示例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);
}
示例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);
}
});
}
示例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;
}
});
}
示例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);
}
});
}
示例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);
}