Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Component;
import java.awt.Dimension;

import java.awt.Toolkit;

public class Main {
    public static void centerOnScreen(Component component, int width, int height) {

        int x = getScreenWidth() / 2 - width / 2;
        int y = getScreenHeight() / 2 - height / 2;

        component.setBounds(x, y, width, height);
    }

    public static int getScreenWidth() {
        Dimension screenSz = Toolkit.getDefaultToolkit().getScreenSize();
        return screenSz.width;
    }

    public static int getScreenHeight() {
        Dimension screenSz = Toolkit.getDefaultToolkit().getScreenSize();
        return screenSz.height;
    }
}