gpt4 book ai didi

java - 如何在全屏独占模式下设置 Java 应用程序的分辨率/系统分辨率?

转载 作者:行者123 更新时间:2023-11-30 06:35:23 25 4
gpt4 key购买 nike

如果有人能指出我正确的方向。这是我到目前为止的代码。

//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setUndecorated(true);//To remove the bars around the frame.
frame.setResizable(false);//resizability causes unsafe operations.

frame.validate();

//actually applies the fullscreen.
GaphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);

最佳答案

您可能对 oracle 教程感兴趣的三个复杂示例。

Do you want to use high-performance graphics in the Java development environment? Have you always wanted to program a game, but your images wouldn't move fast enough? Has your slide show program not worked properly because you had no control over the user's display resolution? If you've been asking any of these questions, then the full-screen exclusive mode API, introduced in release 1.4, may be what you're looking for.


CapabilitiesTest demonstrates the different buffering capabilities available for the machine on which it is run.


DisplayModeTest shows a Swing application that uses passive rendering. If full-screen exclusive mode is available, it will enter full-screen exclusive mode. If display mode changes are allowed, it allows you to switch between display modes.


MultiBufferTest enters full-screen mode and uses multi-buffering through an active render loop.

看看这个:
oracle.com/tutorial/fullscreen

还有这个:
oracle.com/tutorial/fullscreen/example

编辑:

这是一个示例应用程序,可以满足您的需求:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class DisplayModeChanger extends JFrame {

private GraphicsDevice device;
private static JButton changeDM = new JButton("800X600 @ 32 BIT 60HZ");
private boolean isFullScreenSupported = false;

public DisplayModeChanger(final GraphicsDevice device) {

this.device = device;

setDefaultCloseOperation(EXIT_ON_CLOSE);

changeDM.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
DisplayMode dm = new DisplayMode(800, 600, 32, 60);
device.setDisplayMode(dm);
setSize(new Dimension(dm.getWidth(), dm.getHeight()));
validate();
}
});

}

public void goFullScreen() {
isFullScreenSupported = device.isFullScreenSupported();
setUndecorated(isFullScreenSupported);
setResizable(!isFullScreenSupported);
if (isFullScreenSupported) {
device.setFullScreenWindow(this);
validate();
} else {
pack();
setVisible(true);
}
}

public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultScreen = env.getDefaultScreenDevice();
DisplayModeChanger changer = new DisplayModeChanger(defaultScreen);
changer.getContentPane().add(changeDM);
changer.goFullScreen();
}
}

关于java - 如何在全屏独占模式下设置 Java 应用程序的分辨率/系统分辨率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6115537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com