Java program to find current Screen Resolution :
In this tutorial, we will learn how to find the Screen resolution of your system. We will use ‘java.awt’ package to calculate the values.
-
Using ‘Toolkit’ class, get the screen size using ‘Toolkit.getDefaultToolkit().getScreenSize()’ method.
-
’getScreenSize()’ gets the size of the primary display if multiple screens are added.
-
The return value is of type ‘Dimension’
-
We can have the ‘height’ and ‘width’ using ‘getHeight()’ and ‘getWidth()’ methods.
-
The return values of ‘width’ and ‘height’ is in pixel.
Example program :
import java.awt.*;
public class Main {
public static void main(String[] args) {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
short width = (short) size.getWidth();
short height = (short) size.getHeight();
System.out.println("Current Screen resolution : " + "w : " + width + " h : " + height);
}
}
Output :
Current Screen resolution : w : 1366 h : 768
Similar tutorials :
- Java System.nanoTime and System.currentTimeMillis
- Java program to find Permutation and Combination ( nPr and nCr )
- Java Program to find the last non repeating character of a string
- Java Program to find Simple Interest
- Java Program to find Transpose of a matrix
- Java program to find the sum of all digits of a number