Page 1
Index
See this article in english  Ver este artículo en español 
Page 2
Convertir en palabras un número

Getting the screen size in Java

Alexander Hristov

The java.awt.Toolkit acts as a bridge between the OS and Java, centralizing all OS-dependant graphics operations, so that in the same runtime environment may coexist different implementations of the OS/Java boundary. The Toolkit class itself is abstract - the concrete descendents handle the implementation details. We can get the current Toolkit implementation using the getDefaultToolkit() static method

One of the method defined in the class is the getScreenSize() method, that allows us to retrieve the screen size.

 

Dimensiones.java
 
import java.awt.Toolkit;
import java.awt.Dimension;


public class Dimensiones {
  public static void main(String[] args) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension tama?o = tk.getScreenSize();
    System.out.println("La pantalla es de " + tama?o.getWidth() + 
      " x " + tama?o.getHeight() );
  }
}
 


 

Comments

 

Add a Comment

Name (optional)
EMail (optional, will not be displayed)

Text