Java tutorial
//package com.java2s; import javax.swing.*; import java.awt.*; public class Main { public static void run(final JFrame f) { SwingUtilities.invokeLater(new Runnable() { public void run() { f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); f.setExtendedState(f.getExtendedState() | JFrame.MAXIMIZED_BOTH); } }); } public static void run(final JFrame f, final int width, final int height) { SwingUtilities.invokeLater(new Runnable() { public void run() { f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(width, height); f.setVisible(true); moveToCenter(f); } }); } public static void moveToCenter(JFrame frame) { int windowWidth = frame.getWidth(); int windowHeight = frame.getHeight(); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width; int screenHeight = screenSize.height; frame.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2); } }