Java DisplayMode.getWidth()
Syntax
DisplayMode.getWidth() has the following syntax.
public int getWidth()
Example
In the following code shows how to use DisplayMode.getWidth() method.
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
/* w w w . jav a2s .c o m*/
public class Main {
public static void main(String[] argv) throws Exception {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
DisplayMode[] dmodes = gs.getDisplayModes();
for (int i = 0; i < dmodes.length; i++) {
int screenWidth = dmodes[i].getWidth();
int screenHeight = dmodes[i].getHeight();
System.out.println(screenWidth);
System.out.println(screenHeight);
}
}
}
Home »
Java Tutorial »
java.awt »
Java Tutorial »
java.awt »