Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Toolkit;
import java.awt.Window;

public class Main {
    /**
     * Centers a {@link Window} at the center of the screen.<br/>
     * Windows like {@link JDialog} and {@link JFrame} (and others) that extend from {@link Window} applies for this method.
     * 
     * @param window 
     */
    public static void centerWindow(Window window) {
        window.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width) / 2 - window.getWidth() / 2,
                (Toolkit.getDefaultToolkit().getScreenSize().height) / 2 - window.getHeight() / 2);
    }
}