0

您如何应用按键监听器进行双击?也就是说,你打一次它就会打开,然后你再打一次它就会关闭。我可以通过 LWJGL 键盘做到这一点,但不能通过 AWT 的 KeyEvent 做到这一点。你怎么能用 AWT 做到这一点?

我的尝试:

public static void fullscreenKey(KeyEvent e2, JFrame frame)
{
    int key = e2.getKeyCode();
    if(key == KeyEvent.VK_F1)
    {
        fullscreen(false, frame);
        f1 = false;
    }
    if(key == KeyEvent.VK_F1 && !f1)
    {
        fullscreen(true, frame);
        f1 = true;
    }
}

我还需要在其他类中调用这个方法。

4

1 回答 1

2

看来你打fullscreen了两次电话:

public static void fullscreenKey(KeyEvent e2, JFrame frame)
{
    int key = e2.getKeyCode();
    if(key == KeyEvent.VK_F1)
    {
        // This always executes if VK_F1 is pressed,
        // setting f1 to false
        fullscreen(false, frame);
        f1 = false;
    }
    if(key == KeyEvent.VK_F1 && !f1)
    {
        // f1 is now false, so this will execute too!
        fullscreen(true, frame);
        f1 = true;
    }
}

你也许应该尝试:

public static void fullscreenKey(KeyEvent e2, JFrame frame)
{
    int key = e2.getKeyCode();
    if(key == KeyEvent.VK_F1)
    {
        fullscreen(!f1, frame);            
        f1 = !f1;
    }     
}
于 2012-09-03T14:48:39.550 回答