how-to

Graphics

How to get screen size

For this you must use:

import java.awt.*;

VARIANT 1

When you have one screen only:

Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    
System.out.println( size.width + "x" + size.height );

The output could be:

1280x1024

VARIANT 2

Use below code when you have more screens - or when you want to know more information about the screen:

/* -- get screen devices */

GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

/* -- go throught devices and get more informations */

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

  System.out.println( "Bit depth: " + mode.getBitDepth() );
  System.out.println( "Refresh rate: " + mode.getRefreshRate() );

  System.out.println( mode.getWidth() + "x" + mode.getHeight() );

  GraphicsConfiguration conf = devices[i].getDefaultConfiguration();
}

The output could be:

Bit depth: 32
Refresh rate: 60
1280x1024