java get screen size

import java.awt.Dimension;
import java.awt.Toolkit;
 
class ScreenSize {
    public static void main(String[] args)
    {
        // getScreenSize() method returns the size of the screen in pixels
        Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
 
         // getWidth() method returns the height of the screen
        int width = (int)size.getWidth();
 
        // getHeight() method returns the height of the screen
        int height = (int)size.getHeight();
 
        System.out.println("Screen resolution: ");
        System.out.println("Width: " + width);
        System.out.println("Height: " + height);
    }
}

Output:

Screen resolution: 
Width: 1366
Height: 768
Please follow and like us:
Content Protection by DMCA.com