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 javax.swing.JDialog;
import javax.swing.JFrame;

public class Main {
    public static void setCenterOfParent(JFrame parent, JDialog dialog) {
        Point parentPosition = parent.getLocation();
        Dimension parentSize = parent.getSize();
        Dimension size = dialog.getSize();
        Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2),
                parentPosition.y + (parentSize.height / 2 - size.height / 2));
        dialog.setLocation(position);
    }

    public static void setCenterOfParent(JDialog parent, JDialog dialog) {
        Point parentPosition = parent.getLocation();
        Dimension parentSize = parent.getSize();
        Dimension size = dialog.getSize();
        Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2),
                parentPosition.y + (parentSize.height / 2 - size.height / 2));
        dialog.setLocation(position);
    }
}