【问题标题】:Full-Screen Exclusive mode error全屏独占模式错误
【发布时间】:2013-08-05 22:29:37
【问题描述】:

我想使用全屏模式,但是当我按“F”时,我不断收到一个复杂的错误。我正在使用 eclipse,它没有显示任何错误,并且所有内容都已导入。如果有人擅长代码,你能告诉我我做错了什么吗?

一个sn-p的代码:

GraphicsEnviroment ge = GraphicsEnviroment.getLocalGraphicsEnviroment();
GraphicsDevice gd = ge.GetDefaultScreenDevice();
private boolean FullScreen = false;
JFrame frame = new JFrame(TITLE);

// Not shown: The JFrame is set up etc., and a separate class extends KeyAdapter and runs keyPressed

public void keyPressed(KeyEvent e){
    int key = e.getKeyCode();
        if(key == KeyEvent.VK_F){
        if(!FullScreen){
            if(gd.isFullScreenSupported()){
                frame.setUndecorated(true);
                gd.setFullScreenWindow(frame);
                                    FullScreen = true;
            }
        } else{
            frame.setUndecorated(false);
            gd.setFullScreenWindow(null);
        }
    }

错误:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable.
at java.awt.Frame.setUndecorated(Frame.java:923)
at com.Ward.src.main.Game.keyPressed(Game.java:167)
at com.Ward.src.main.KeyboardInput.keyPressed(KeyboardInput.java:15)
at java.awt.Component.processKeyEvent(Component.java:6463)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

【问题讨论】:

    标签: java exception graphics jframe fullscreen


    【解决方案1】:
    frame.dispose(); // Fixes the issue
    frame.setUndecorated(true);
    frame.setVisible();
    

    我知道这个问题很老,但是我自己处理了这个问题,解决方案对我来说很好。

    【讨论】:

      【解决方案2】:

      您需要将gd初始化为GraphicsEnvironment.getGraphicsEnvironment.getDefaultScreenDevice()才能使用它。

      更新: 既然 OP 已经解决了这个问题,还有另一个问题。问题是在已经显示的窗口上更改undecorated 属性。如果正在显示窗口,则无法更改undecorated 属性,因为操作系统无法在显示时更改该属性。我认为这可以通过省略对setUndecorated 的调用来解决,全屏窗口不必不装饰(我认为)。

      【讨论】:

      • 我替换了 GraphicsDevice gd;与 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice();但我仍然得到错误!救命!
      【解决方案3】:

      这是:

      if(gd.isFullScreenSupported()){
      

      第 165 行?如果是这样,gd set 是什么?

      上述异常为您提供了发生错误的类/行号。这应该足以让您了解什么是空的。

      【讨论】:

      • 我认为 frame.setUndecorated(true);现在返回一个错误。那会返回错误吗?
      【解决方案4】:

      仅在您的代码中添加“setUndecorated(true)”。 示例:

      public launch() {
      
          setSize(300, 200);
          setUndecorated(true);
      
      }
      

      【讨论】:

        猜你喜欢
        • 2014-05-18
        • 2012-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多