Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;

import javax.swing.JFrame;

public class Main {
    public static void centerFrame(JFrame frame) {
        GraphicsDevice defaultScreen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        Rectangle screenSize = defaultScreen.getDefaultConfiguration().getBounds();

        int midx = screenSize.width / 2;
        int midy = screenSize.height / 2;

        int posx = midx - (frame.getWidth() / 2);
        int posy = midy - (frame.getHeight() / 2);

        frame.setLocation(posx, posy);
    }
}