is X On Screen - Java Swing

Java examples for Swing:Screen

Description

is X On Screen

Demo Code


//package com.java2s;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

public class Main {
    public static boolean isXOnScreen(int x) {
        GraphicsDevice[] devices = GraphicsEnvironment
                .getLocalGraphicsEnvironment().getScreenDevices();
        for (GraphicsDevice device : devices) {
            int boundA = device.getDefaultConfiguration().getBounds().x;
            int boundB = boundA
                    + device.getDefaultConfiguration().getBounds().width;
            if (inBounds(x, boundA, boundB)) {
                return true;
            }/*from   ww  w  .j a  v a  2s . c o m*/
        }
        return false;
    }

    private static boolean inBounds(int x, int boundA, int boundB) {
        if (boundA < boundB) {
            return x >= boundA && x <= boundB;
        }
        return x <= boundA && x >= boundB;
    }
}

Related Tutorials