全屏独占模式错误 [英] Full-Screen Exclusive mode error

查看:154
本文介绍了全屏独占模式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



代码片段:

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

//未显示:JFrame设置等,一个单独的类扩展KeyAdapter并运行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);




$ b

错误:

 线程中的异常AWT-EventQueue-0java.awt.IllegalComponentStateException:该框架是可显示的。 
在java.awt.Frame.setUndecorated(Frame.java:923)
在com.Ward.src.main.Game.keyPressed(Game.java:167)
在com.Ward .src.main.KeyboardInput.keyPressed(KeyboardInput.java:15)$ b $在java.awt.Component.processKeyEvent(Component.java:6463)
在java.awt.Component.processEvent(Component.java (Component.java:4861)
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)
a java.awt.Component.dispatchEvent(Component.java:4687)$ b $在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
在java.awt.EventQueue.access $ 200(EventQueue。 java:103)
at java.awt.EventQueue $ 3.run(EventQueue.java:694)$ b $ at java.awt.EventQueue $ 3.run(EventQueue.java:692)
at java .security.AccessController.doPrivileged(本地方法)$ java.util.ProtectionDomain
$ 1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:87)在java.awt.EventQueue
$ 4.run(EventQueue.java:708)$ b $在java.awt.EventQueue $ 4.run(EventQueue.java:706)
在java.security.AccessController .doPrivileged(本地方法)$ java.util.ProtectionDomain
$ 1.doIntersectionPrivilege(ProtectionDomain.java:76)$ b $ at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
在java.awt.EventDispatchThread。 pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
gd
初始化为 GraphicsEnvironment。

getGraphicsEnvironment.getDefaultScreenDevice(),然后才能使用它。

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


I want to use Full Screen mode, but I keep getting a complicated error when I press "F". I am using eclipse and it does not show any errors and everything is imported. If anyone is good with code, can you tell me what I did wrong?

A snippet of the code:

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);
        }
    }

The error:

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)

解决方案

You need to initialize gd to GraphicsEnvironment.getGraphicsEnvironment.getDefaultScreenDevice() before you can use it.

Update: Now that the OP has fixed this problem, there is another problem. The problem is changing the undecorated property on a window that is already being displayed. If the window is being displayed, the undecorated property can't be changed, because the operating system can't change the property while it is displayed. I think this can be fixed by omitting the call to setUndecorated, the full screen window doesn't have to be undecorated (I think).

这篇关于全屏独占模式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆