How do I find out the screen size of the user's machine?

John Zukowski

The AWT Toolkit object provides information about the user's runtime platform. To find out what size in pixels the users's screen is, use the getScreenSize() method.

import java.awt.*;
public class Size {
  public static void main(String args[]) {
    // Get toolkit
    Toolkit toolkit = Toolkit.getDefaultToolkit();

    // Get size
    Dimension dimension = toolkit.getScreenSize();

    // Print size
    System.out.println ("Width: " + dimension.width);
    System.out.println ("Height: " + dimension.height);

    // Force exit
    System.exit(0);
  }
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact