y += 20;
}
Rectangle desired = new Rectangle(x, y, 50, 50);
int gcBestSize = 0;
Point gcBestPoint = null;
GraphicsEnvironment ge;
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (GraphicsDevice gd : ge.getScreenDevices()) {
for (GraphicsConfiguration gc : gd.getConfigurations()) {
Rectangle gcBounds = gc.getBounds();
if (gcBounds.intersects(desired)) {
Rectangle inter = gcBounds.intersection(desired);
int size = inter.width * inter.height;
if (size > gcBestSize) {
gcBestSize = size;
int x2 = Math.max(gcBounds.x, Math.min(inter.x,
inter.x + inter.width - 50));
int y2 = Math.max(gcBounds.y, Math.min(inter.y,
inter.y + inter.height - 50));
gcBestPoint = new Point(x2, y2);
}
}
}
}
if (gcBestPoint != null) {