is Y On Screen - Java Swing

Java examples for Swing:Screen

Description

is Y On Screen

Demo Code


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

public class Main {
    public static boolean isYOnScreen(int y) {
        GraphicsDevice[] devices = GraphicsEnvironment
                .getLocalGraphicsEnvironment().getScreenDevices();
        for (GraphicsDevice device : devices) {
            int boundA = device.getDefaultConfiguration().getBounds().y;
            int boundB = boundA
                    + device.getDefaultConfiguration().getBounds().height;
            if (inBounds(y, boundA, boundB)) {
                return true;
            }/*from   w  ww  .j  a  v a 2 s .  com*/
        }
        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