Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Dimension;

import java.awt.Point;
import java.awt.Toolkit;

public class Main {
    /**
     * Returns a <code>Point</code> used as location for a window that
     * should be centered on the screen.
     * 
     * @param size a <code>Dimension</code> describing the window's size
     * @return a <code>Point</code> describing the top-left position
     */
    public static Point getCenteredLocation(Dimension size) {

        final Toolkit tk = Toolkit.getDefaultToolkit();
        final Dimension screenSize = tk.getScreenSize();

        return new Point(((screenSize.width - size.width) / 2), ((screenSize.height - size.height) / 2));
    }
}