简体   繁体   中英

How to program a full-screen mode in Java?

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?

Try the Full-Screen Exclusive Mode API . It was introduced in the JDK in release 1.4. Some of the features include:

  • 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.

There are several full-screen exclusive mode examples in the linked tutorial.

JFrame setUndecorated(true)方法

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.

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).

It really depends on what you're using to display your interface, ie AWT/Spring or OpenGL etc.

Java has a full screen exclusive mode API - see this tutorial from Sun .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM