Calculates the center point of the first available graphics device (screen). - Java java.lang

Java examples for java.lang:int prime

Description

Calculates the center point of the first available graphics device (screen).

Demo Code


//package com.java2s;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;

public class Main {
    /**/*from   w  ww. j  av  a  2 s  . com*/
     * Calculates the center point of the first available graphics device
     * (screen).
     *
     * @return
     */
    public static Point getFirstScreenCenter() {
        GraphicsEnvironment gEnvironment = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = gEnvironment.getScreenDevices();
        if (devices.length < 1) {
            return new Point(0, 0);
        }
        DisplayMode displayMode = devices[0].getDisplayMode();
        return new Point(displayMode.getWidth() / 2,
                displayMode.getHeight() / 2);

    }
}

Related Tutorials