The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > The Screen  [8 examples]

e604. Getting the Current Screen Refresh Rate and Number of Colors

This example retrieves the refresh rate (in Hz) and number of supported colors for all screens.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    
    for (int i=0; i<gs.length; i++) {
        DisplayMode dm = gs[i].getDisplayMode();
    
        // Get refresh rate in Hz
        int refreshRate = dm.getRefreshRate();
        if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
            // Unknown rate
        }
    
        // Get number of colors
        int bitDepth = dm.getBitDepth();
        if (bitDepth == DisplayMode.BIT_DEPTH_MULTI) {
            // Multiple bit depths are supported in this display mode
        } else {
            int numColors = (int)Math.pow(2, bitDepth);
        }
    }

 Related Examples
e598. Getting the Screen Size
e599. Centering a Frame, Window, or Dialog on the Screen
e600. Getting the Number of Screens
e601. Enabling Full-Screen Mode
e602. Double-Buffering in Full-Screen Mode
e603. Getting the Available Screen Sizes, Refresh Rates, and Number of Colors
e605. Setting the Screen Size, Refresh Rate, or Number of Colors

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    Frames    GridBagLayout    Images    Shapes    Simulating Events    Text   


© 2002 Addison-Wesley.