Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JFrame;
import javax.swing.JDialog;

import java.awt.Dimension;
import java.awt.Toolkit;

public class Main {
    /**
     * Center JFrame.
     */
    public static void center(JFrame frame) {
        Dimension frameSize = frame.getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1);
    }

    /**
     * Center JDialog.
     */
    public static void center(JDialog dialog) {
        Dimension dialogSize = dialog.getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        dialog.setLocation((screenSize.width - dialogSize.width) >> 1,
                (screenSize.height - dialogSize.height) >> 1);
    }
}