Example usage for java.awt DisplayMode getRefreshRate

List of usage examples for java.awt DisplayMode getRefreshRate

Introduction

In this page you can find the example usage for java.awt DisplayMode getRefreshRate.

Prototype

public int getRefreshRate() 

Source Link

Document

Returns the refresh rate of the display, in hertz.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();

    DisplayMode[] dmodes = gs.getDisplayModes();
    for (int i = 0; i < dmodes.length; i++) {
        DisplayMode dm = dmodes[i];
        int refreshRate = dm.getRefreshRate();
        System.out.println(refreshRate);
    }// w  w  w.j  a va2s  .c  o m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();

    for (int i = 0; i < gs.length; i++) {
        DisplayMode dm = gs[i].getDisplayMode();

        int refreshRate = dm.getRefreshRate();
        if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
            System.out.println("Unknown rate");
        }//from   w  w w  . j  a v a 2s .c  om

        int bitDepth = dm.getBitDepth();
        int numColors = (int) Math.pow(2, bitDepth);
    }
}

From source file:Main.java

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 {//from  ww  w.  j a  v a2 s.co m
            gs.setDisplayMode(displayMode);
        } catch (Throwable e) {
            gs.setFullScreenWindow(null);
        }
    }
}

From source file:DisplayModeModel.java

public void setDMLabel(DisplayMode newMode) {
    int bitDepth = newMode.getBitDepth();
    int refreshRate = newMode.getRefreshRate();
    String bd, rr;//from ww  w. j a v  a2  s. c o  m
    if (bitDepth == DisplayMode.BIT_DEPTH_MULTI) {
        bd = "Multi";
    } else {
        bd = Integer.toString(bitDepth);
    }
    if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
        rr = "Unknown";
    } else {
        rr = Integer.toString(refreshRate);
    }
    currentDM.setText(COLUMN_NAMES[INDEX_WIDTH] + ": " + newMode.getWidth() + " " + COLUMN_NAMES[INDEX_HEIGHT]
            + ": " + newMode.getHeight() + " " + COLUMN_NAMES[INDEX_BITDEPTH] + ": " + bd + " "
            + COLUMN_NAMES[INDEX_REFRESHRATE] + ": " + rr);
}

From source file:DisplayModeModel.java

public Object getValueAt(int rowIndex, int colIndex) {
    DisplayMode dm = modes[rowIndex];
    switch (colIndex) {
    case DisplayModeTest.INDEX_WIDTH:
        return Integer.toString(dm.getWidth());
    case DisplayModeTest.INDEX_HEIGHT:
        return Integer.toString(dm.getHeight());
    case DisplayModeTest.INDEX_BITDEPTH: {
        int bitDepth = dm.getBitDepth();
        String ret;//from   ww  w .j  ava 2 s .c om
        if (bitDepth == DisplayMode.BIT_DEPTH_MULTI) {
            ret = "Multi";
        } else {
            ret = Integer.toString(bitDepth);
        }
        return ret;
    }
    case DisplayModeTest.INDEX_REFRESHRATE: {
        int refreshRate = dm.getRefreshRate();
        String ret;
        if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
            ret = "Unknown";
        } else {
            ret = Integer.toString(refreshRate);
        }
        return ret;
    }
    }
    throw new ArrayIndexOutOfBoundsException("Invalid column value");
}

From source file:Filter3dTest.java

/**
 * Determines if two display modes "match". Two display modes match if they
 * have the same resolution, bit depth, and refresh rate. The bit depth is
 * ignored if one of the modes has a bit depth of
 * DisplayMode.BIT_DEPTH_MULTI. Likewise, the refresh rate is ignored if one
 * of the modes has a refresh rate of DisplayMode.REFRESH_RATE_UNKNOWN.
 *///from  ww  w  .j av  a 2 s  .c o m
public boolean displayModesMatch(DisplayMode mode1, DisplayMode mode2)

{
    if (mode1.getWidth() != mode2.getWidth() || mode1.getHeight() != mode2.getHeight()) {
        return false;
    }

    if (mode1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && mode2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI
            && mode1.getBitDepth() != mode2.getBitDepth()) {
        return false;
    }

    if (mode1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN
            && mode2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN
            && mode1.getRefreshRate() != mode2.getRefreshRate()) {
        return false;
    }

    return true;
}