public void fullscreenKey(final JFrame frame)
{
k = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
getInputMap(WHEN_IN_FOCUSED_WINDOW).put(k, k.toString());
getActionMap().put(k.toString(), new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
fullscreen(!f1, frame);
f1 = !f1;
}
});
}
每當我將此方法調用到其他類中時,什麼都不會發生。由於getInputMap和getActionMap,我不能使這個方法是靜態的。我使用Main main = new Main(); main.fullscreenKey(幀);這個方法在Main構造函數中被調用。我如何在其他類中調用此方法並使其工作?雙擊鍵盤綁定Java
只是要getInputMap中和getActionMap靜態的呢? –
@JeffLaJoie'getInputMap'和'getActionMap'是'JComponent'的方法,它們是[Swing key bindings API]的一部分(http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html ),他不能讓他們靜態 – MadProgrammer