Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {

    public static void main(String[] args) {
        JButton close = new JButton("Close me programmatically");
        final JFrame f = new JFrame("Close Me");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(close);
        close.addActionListener(e -> {
            f.dispose();
        });
        f.pack();
        f.setLocationByPlatform(true);
        f.setVisible(true);
    }
}