import javax.swing.JFrame; class Program01 extends JFrame { Program01() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); centerWindow(this); setVisible(true); } public static void centerWindow(java.awt.Window frame) { java.awt.Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); } public static void main(String[] args) { new Program01(); } }