Java tutorial
//package com.java2s; import java.awt.Toolkit; import java.awt.event.WindowEvent; import javax.swing.JFrame; public class Main { /** * Closes the given {@link JFrame}. * * @param win * - the frame to close */ public static void kill(JFrame win) { if (win == null) { return; } WindowEvent close = new WindowEvent(win, WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(close); } }