Java Swing Tutorial - Java DisplayMode(int width, int height, int bitDepth, int refreshRate) Constructor








Syntax

DisplayMode(int width, int height, int bitDepth, int refreshRate) constructor from DisplayMode has the following syntax.

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

Example

In the following code shows how to use DisplayMode.DisplayMode(int width, int height, int bitDepth, int refreshRate) constructor.

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
//ww w .  jav  a  2s. c  om
public class Main {
  public static void main(String[] argv) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();

    boolean canChg = gs.isDisplayChangeSupported();
    if (canChg) {
      DisplayMode displayMode = gs.getDisplayMode();
      int screenWidth = 640;
      int screenHeight = 480;
      int bitDepth = 8;
      displayMode = new DisplayMode(screenWidth, screenHeight, bitDepth, displayMode
          .getRefreshRate());
      try {
        gs.setDisplayMode(displayMode);
      } catch (Throwable e) {
        gs.setFullScreenWindow(null);
      }
    }
  }
}