Java Swing Tutorial - Java Toolkit.getScreenSize()








Syntax

Toolkit.getScreenSize() has the following syntax.

public abstract Dimension getScreenSize()     throws HeadlessException

Example

In the following code shows how to use Toolkit.getScreenSize() method.

import java.awt.Dimension;
import java.awt.Toolkit;
//  w w w.j a v a2s.  c  o  m
public class Main {
  public static void main(String[] args) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    System.out.println("Screen width = " + d.width);
    System.out.println("Screen height = " + d.height);

  }
}

The code above generates the following result.