Java tutorial
import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class Main extends JFrame { public Main() throws HeadlessException { this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); JButton button = new JButton("Close"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); this.setLayout(new FlowLayout(FlowLayout.CENTER)); this.setSize(new Dimension(100, 100)); this.getContentPane().add(button); } public static void main(String[] args) { new Main().setVisible(true); } }