本文整理匯總了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);
}