【发布时间】:2012-09-06 04:46:13
【问题描述】:
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(frame);此方法在 Main 构造函数中调用。如何在其他类中调用此方法并使其工作?
【问题讨论】:
-
把getInputMap 和getActionMap 也设为静态?
-
@JeffLaJoie
getInputMap和getActionMap是JComponent的方法,它们构成了 Swing key bindings API 的一部分,他不能将它们设为静态
标签: java swing jframe fullscreen key-bindings