當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。