Source Code : Verifies if the given point is visible on the screen.
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Verifies if the given point is visible on the screen.
//package com.javadocking.util;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
/**
* This class contains a collection of static utility methods for Swing.
*
* @author Heidi Rakels.
*/
public class SwingUtil
{
/**
* Verifies if the given point is visible on the screen.
*
* @param location The given location on the screen.
* @return True if the location is on the screen, false otherwise.
*/
public static boolean isLocationInScreenBounds(Point location)
{
// Check if the location is in the bounds of one of the graphics devices.
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
Rectangle graphicsConfigurationBounds = new Rectangle();
// Iterate over the graphics devices.
for (int j = 0; j < graphicsDevices.length; j++) {
// Get the bounds of the device.
GraphicsDevice graphicsDevice = graphicsDevices[j];
graphicsConfigurationBounds.setRect(graphicsDevice.getDefaultConfiguration().getBounds());
// Is the location in this bounds?
graphicsConfigurationBounds.setRect(graphicsConfigurationBounds.x, graphicsConfigurationBounds.y,
graphicsConfigurationBounds.width, graphicsConfigurationBounds.height);
if (graphicsConfigurationBounds.contains(location.x, location.y)) {
// The location is in this screengraphics.
return true;
}
}
// We could not find a device that contains the given point.
return false;
}
}
Thank with us