如何在 Java 中将我的框架设置为无边框全屏、窗口全屏和全屏?

How do I set my frames to Borderless Fullscreen, Windowed Fullscreen, and Fullscreen in Java?

我使用 GraphicsDevice 全屏 Java Window,但我不知道如何在应用程序 运行ning 时更改这些设置。

public void act(java.awt.Frame window) {
        if (state == SCREEN.FULLSCREEN) {
            if (ev.isFullScreenSupported()) {
                isFullScreen = true;
                window.dispose();
                ev.setFullScreenWindow(window);
                window.setVisible(true);
            }
        }
        if (state == SCREEN.WINDOWED) {
            isFullScreen = false;
            window.dispose();
            ev.setFullScreenWindow(null);
            window.setUndecorated(false);
            window.setVisible(true);
        }
        if (state == SCREEN.BORDERLESS) {
            isFullScreen = true;
            window.dispose();
            ev.setFullScreenWindow(null);
            window.setUndecorated(true);
            window.setVisible(true);
        }
    }

当我无限地 运行 时,代码只是一遍又一遍地创建一个新的 window,但我想让它根据 [=12= 的值改变屏幕].

虽然我不得不改变周围的参数,但它很简单。 对于字段,您需要:

    public enum ScreenState {
        fullscreen, borderless, windowed, none
    };
    public static ScreenState current;
    private static GraphicsEnvironment env = 
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    private static GraphicsDevice ev = env.getDefaultScreenDevice();

对于该方法,您可以执行以下操作:

public void changeWindow(ScreenState applied, JFrame frame) {

        if (applied == ScreenState.fullscreen && current != ScreenState.fullscreen) {
            if (ev.isFullScreenSupported()) {
                ev.setFullScreenWindow(frame);
            }
            current =  ScreenState.fullscreen;
        }
        if (applied == ScreenState.borderless && current != ScreenState.borderless) {
            frame.setUndecorated(true);
            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
            current =  ScreenState.borderless;
        }
        if (applied == ScreenState.windowed && current != ScreenState.windowed) {
            frame.setUndecorated(false);
            // you can choose to make the screen fit or not
            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
            current =  ScreenState.windowed;
        }
    }

感谢大家花时间帮助我!