java get screen size

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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);
}
}
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); } }
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Screen resolution:
Width: 1366
Height: 768
Screen resolution: Width: 1366 Height: 768
Screen resolution: 
Width: 1366
Height: 768