Java set display mode

Lesson: Full-Screen Exclusive Mode API

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.

Full-Screen Exclusive Mode Full-screen exclusive mode is a powerful new feature that enables you to suspend the windowing system so that drawing can be done directly to the screen. Display Mode This section describes how to choose and set the display mode. It also discusses why you’d want to set the display mode in the first place. Passive vs. Active Rendering This section discusses the merits of passive and active rendering. For example, painting while on the main event loop using the paint method is passive, whereas rendering in your own thread is active. Active rendering tips are also listed. Double Buffering and Page Flipping This section explains double buffering and introduces page-flipping, a double buffering technique available in full-screen exclusive mode. BufferStrategy and BufferCapabilities This section covers java.awt.image.BufferStrategy , a class that allows you to draw to surfaces and components without having to know the number of buffers used or the technique used to display them. This section also reviews java.awt.BufferCapabilities , a class that can help you determine the capabilities of your graphics device. Examples This page lists several full-screen exclusive mode examples.

Читайте также:  Html script math floor

Источник

Class DisplayMode

The DisplayMode class encapsulates the bit depth, height, width, and refresh rate of a GraphicsDevice . The ability to change graphics device’s display mode is platform- and configuration-dependent and may not always be available (see GraphicsDevice.isDisplayChangeSupported() ).

For more information on full-screen exclusive mode API, see the Full-Screen Exclusive Mode API Tutorial.

Field Summary

Constructor Summary

Method Summary

Methods declared in class java.lang.Object

Field Details

BIT_DEPTH_MULTI

REFRESH_RATE_UNKNOWN

Constructor Details

DisplayMode

Method Details

getHeight

getWidth

getBitDepth

Returns the bit depth of the display, in bits per pixel. This may be BIT_DEPTH_MULTI if multiple bit depths are supported in this display mode.

getRefreshRate

Returns the refresh rate of the display, in hertz. This may be REFRESH_RATE_UNKNOWN if the information is not available.

equals

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Display Mode

Once an application is in full-screen exclusive mode, it may be able to take advantage of actively setting the display mode. A display mode (java.awt.DisplayMode) is 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). Some operating systems allow you to use multiple bit depths at the same time, in which case the special value BIT_DEPTH_MULTI is used for the value of bit depth. Also, some operating systems may not have any control over the refresh rate (or you may not care about the refresh rate setting). In this case, the special value REFRESH_RATE_UNKNOWN is used for the refresh rate value.

Читайте также:  Crfxfnm java jre x32

How to Set the Display Mode

To get the current display mode, simply call the getDisplayMode method on your graphics device. To obtain a list of all possible display modes, call the getDisplayModes method. Both getDisplayMode and getDisplayModes can be called at any time, regardless of whether or not you are in full-screen exclusive mode.

Before attempting to change the display mode, you should first call the isDisplayChangeSupported method. If this method returns false, the operating system does not support changing the display mode.

Changing the display mode can only be done when in full-screen exclusive mode. To change the display mode, call the setDisplayMode method with the desired display mode. A runtime exception will be thrown if the display mode is not available, if display mode changes are not supported, or if you are not running in full-screen exclusive mode.

Reasons for Changing the Display Mode

The main reason for setting the display mode is performance. An application can run much more quickly if the images it chooses to display share the same bit depth as the screen. Also, if you can count on the display to be a particular size, it makes drawing to that display much simpler, since you do not have to scale things down or up depending on how the user has set the display.

Programming Tips

Here are some tips for choosing and setting the display mode:

  • Check the value returned by the isDisplayChangeSupported method before attempting to change the display mode on a graphics device.
  • Make sure you are in full-screen exclusive mode before attempting to change the display mode.
  • As with using full-screen mode, setting the display mode is more robust when in a try. finally clause:

GraphicsDevice myDevice; Window myWindow; DisplayMode newDisplayMode; DisplayMode oldDisplayMode = myDevice.getDisplayMode(); try < myDevice.setFullScreenWindow(myWindow); myDevice.setDisplayMode(newDisplayMode); . >finally

Источник

Java set display mode

The DisplayMode class encapsulates the bit depth, height, width, and refresh rate of a GraphicsDevice . The ability to change graphics device’s display mode is platform- and configuration-dependent and may not always be available (see GraphicsDevice.isDisplayChangeSupported() ). For more information on full-screen exclusive mode API, see the Full-Screen Exclusive Mode API Tutorial.

Field Summary

Constructor Summary

Method Summary

Methods declared in class java.lang.Object

Field Detail

BIT_DEPTH_MULTI

@Native public static final int BIT_DEPTH_MULTI

REFRESH_RATE_UNKNOWN

@Native public static final int REFRESH_RATE_UNKNOWN

Constructor Detail

DisplayMode

public DisplayMode​(int width, int height, int bitDepth, int refreshRate)

Method Detail

getHeight

getWidth

getBitDepth

Returns the bit depth of the display, in bits per pixel. This may be BIT_DEPTH_MULTI if multiple bit depths are supported in this display mode.

getRefreshRate

public int getRefreshRate()

Returns the refresh rate of the display, in hertz. This may be REFRESH_RATE_UNKNOWN if the information is not available.

equals

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Оцените статью