Java tutorial
import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Add a close button JButton closeButton = new JButton("Close"); contentPane.add(closeButton); closeButton.addActionListener(e -> { System.out.println(e.getActionCommand()); System.exit(0); }); frame.pack(); frame.setVisible(true); } }