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.Window;

public class Main {
    /**
     * Center the given <code>windows</code> in relative to the given <code>invoker</code>.
     * @param invoker Reference window for the window to center.
     * @param window The window instance to center.
     */
    public static void centerOnWindow(Window invoker, Window window) {
        Point invokerLocationOnScreen = invoker.getLocationOnScreen();
        Dimension invokerSize = invoker.getSize();
        Dimension windowSize = window.getSize();

        window.setLocation(invokerLocationOnScreen.x + (invokerSize.width / 2) - (windowSize.width / 2),
                invokerLocationOnScreen.y + ((invokerSize.height / 2) - (windowSize.height / 2) / 2));
    }
}