Java Program to Print Screen Resolution
Last Updated :
22 Dec, 2020
Screen resolution can be obtained through a Java program by using Toolkit.getScreenSize() method. getScreenSize() is a method of the java Toolkit class of java.awt package. It gets the size of the screen. On systems with multiple displays, the primary display screen resolution is returned.
- Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
- getScreenSize will return the size in pixel.
- If directly size is printed, then it is displayed in the format: java.awt.Dimension[width=1366, height=768]
Declaration
public abstract Dimension getScreenSize()
Returns: The size of the current screen in pixels
Exception
HeadlessException (if GraphicsEnvironment.isHeadless() returns true)
Java
import java.awt.*;
class GFG {
public static void main(String[] args)
{
Dimension size
= Toolkit.getDefaultToolkit().getScreenSize();
int width = ( int )size.getWidth();
int height = ( int )size.getHeight();
System.out.println( "Current Screen resolution : "
+ "width : " + width
+ " height : " + height);
}
}
|
Output:
Share your thoughts in the comments
Please Login to comment...