import javax.swing.JFrame; import java.awt.event.WindowListener; import java.awt.event.WindowEvent; class Program01 extends JFrame { Program01() { addWindowListener(new WindowListener(){ public void windowDeactivated(WindowEvent event) {} public void windowActivated(WindowEvent event) {} public void windowDeiconified(WindowEvent event) {} public void windowIconified(WindowEvent event) {} public void windowClosed(WindowEvent event) {} public void windowClosing(WindowEvent event) {} public void windowOpened(WindowEvent event) {} }); 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(); } }