如何在 Java 中编程全屏模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/139025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to program a full-screen mode in Java?
提问by Epaga
I'd like my application to have a full-screen mode. What is the easiest way to do this, do I need a third party library for this or is there something in the JDK that already offers this?
我希望我的应用程序具有全屏模式。执行此操作的最简单方法是什么,我是否需要为此使用第三方库,或者 JDK 中是否已经提供了此功能?
回答by Bill the Lizard
Try the Full-Screen Exclusive Mode API. It was introduced in the JDK in release 1.4. Some of the features include:
试试全屏独占模式 API。它是在 JDK 1.4 版中引入的。其中一些功能包括:
- Full-Screen Exclusive Mode- allows you to suspend the windowing system so that drawing can be done directly to the screen.
- Display Mode- composed of the size (width and height of the monitor, in pixels), bit depth (number of bits per pixel), and refresh rate (how frequently the monitor updates itself).
- Passive vs. Active Rendering- painting while on the main event loop using the paint method is passive, whereas rendering in your own thread is active.
- Double Buffering and Page Flipping- Smoother drawing means better perceived performance and a much better user experience.
- BufferStrategy and BufferCapabilities- classes that allow you to draw to surfaces and components without having to know the number of buffers used or the technique used to display them, and help you determine the capabilities of your graphics device.
- 全屏独占模式- 允许您暂停窗口系统,以便可以直接在屏幕上进行绘图。
- 显示模式- 由大小(显示器的宽度和高度,以像素为单位)、位深度(每个像素的位数)和刷新率(显示器自身更新的频率)组成。
- 被动与主动渲染- 在主事件循环上使用paint方法进行绘制是被动的,而在您自己的线程中进行渲染是主动的。
- 双缓冲和页面翻转- 更流畅的绘图意味着更好的感知性能和更好的用户体验。
- BufferStrategy 和 BufferCapabilities- 允许您在无需知道使用的缓冲区数量或用于显示它们的技术的情况下绘制表面和组件的类,并帮助您确定图形设备的功能。
There are several full-screen exclusive mode examples in the linked tutorial.
链接教程中有几个全屏独占模式示例。
回答by Ken
JFrame setUndecorated(true)method
JFramesetUndecorated(true)方法
回答by iptq
Use this code:
使用此代码:
JFrame frame = new JFrame();
// set properties
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setUndecorated(true);
frame.setVisible(true);
Make sure setUndecorated()comes before setVisible()or it won't work.
确保setUndecorated()出现在之前,setVisible()否则它将不起作用。
回答by JeeBee
I've done this using JOGL when having a full screen OpenGL user interface for a game. It's quite easy. I believe that the capability was added to Java with version 5 as well, but it's so long ago that I've forgotten how to do it (edit: see answer above for how).
当有一个游戏的全屏 OpenGL 用户界面时,我已经使用 JOGL 完成了这项工作。这很容易。我相信 Java 版本 5 中也添加了该功能,但很久以前我忘记了如何去做(编辑:请参阅上面的答案了解如何)。
回答by Max Stewart
It really depends on what you're using to display your interface, i.e. AWT/Spring or OpenGL etc.
这实际上取决于您用于显示界面的内容,即 AWT/Spring 或 OpenGL 等。
Java has a full screen exclusive mode API - see this tutorial from Sun.
Java 有一个全屏独占模式 API -请参阅 Sun 的本教程。

