is Rectangle Displayable On Screen - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

is Rectangle Displayable On Screen

Demo Code

/*******************************************************************************
    Copyright 2014 Pawel Pastuszak// w ww.j av a2 s  .c  o  m
         
    This file is part of Arget.

    Arget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Arget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Arget.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
//package com.java2s;

import java.awt.GraphicsDevice;

import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

public class Main {
    public static boolean isRectangleDisplayableOnScreen(Rectangle rect) {
        GraphicsDevice[] gd = getScreenDevices();

        for (int i = 0; i < gd.length; i++) {
            Rectangle screen = gd[i].getDefaultConfiguration().getBounds();
            if (screen.contains(rect))
                return true;
        }

        return false;
    }

    public static GraphicsDevice[] getScreenDevices() {
        return GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getScreenDevices();
    }
}

Related Tutorials