Java tutorial
import java.awt.Container; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; class CloseAction extends AbstractAction { public CloseAction() { super("Close"); } @Override public void actionPerformed(ActionEvent event) { System.exit(0); } } public class Main { public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton closeButton = new JButton(new CloseAction()); contentPane.add(closeButton); frame.pack(); frame.setVisible(true); } }