Home Java Java-get-example Java get Screen Dimensions

Related Tutorials


 
 

Share on Google+Share on Google+

Java get Screen Dimensions

Advertisement
In this section, you will learn how to obtain the height and width of the specific screen.

Java get Screen Dimensions

     

In this section, you will learn how to obtain the height and width of the specific screen.

The Toolkit class has a static method called getDefaultToolkit() and can be used to obtain the default Toolkit object for the user's system, which contains information about the user's specific machine. The method getScreenSize() return a Dimension object which contains the width and height of the screen.

 

 

 

Here is the source code of GetScreenSize.java

import java.awt.*;
public class GetScreenSize
{
  public static void main(String[] args){
  Toolkit toolkit =  Toolkit.getDefaultToolkit ();
  Dimension dim = toolkit.getScreenSize();
  System.out.println("Width of Screen Size is "+dim.width+" pixels");
  System.out.println("Height of Screen Size is "+dim.height+" pixels");
  }
}

Output will be displayed as:

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 1, 2008

Related Tutorials

Discuss: Java get Screen Dimensions  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
aetherX
December 19, 2011
Inefficient...

Instead of creating an instance of the toolkit just to use it once, and an instance of the dimension, again to just use it once, just do System.out.println(Toolkit.getDefaultToolkit().getScreenSize.width); and System.out.println(Toolkit.getDefaultToolkit().getScreenSize.height); This is a lot better... trust me.
Hamlet
February 21, 2012
Using this on CF?

Very nice! How would you use this in ColdFusion?
DMCA.com