Here you can find the source of setCenteredRectangle(int rectangleWidth, int rectangleHeight)
public static Rectangle setCenteredRectangle(int rectangleWidth, int rectangleHeight)
//package com.java2s; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Toolkit; public class Main { public static Rectangle setCenteredRectangle(int rectangleWidth, int rectangleHeight) { Dimension screenDimensions = Toolkit.getDefaultToolkit() .getScreenSize();//from w ww . jav a 2s . c o m int xCenter = (screenDimensions.width - rectangleWidth) / 2; int yCenter = (screenDimensions.height - rectangleHeight) / 2; return new Rectangle(xCenter, yCenter, rectangleWidth, rectangleHeight); } }